Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
✨ add support for pure PVP server | 添加纯PVP服支持
Browse files Browse the repository at this point in the history
🐛 fix Crash when no 'S' map | 修复无生存图崩溃的bug
✨ auto quit PVP when no player | 无玩家时自动退出PVP地图
✨ add map mode prefix 'C' 'E' | 增加地图模式前缀C,E

🔖 Update to 1.2.1
  • Loading branch information
way-zer committed Feb 23, 2020
1 parent 75f4854 commit ac6a897
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
2 changes: 1 addition & 1 deletion MindustryPlugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.41'
}
group 'cf.wayzer'
version '1.2.0.1'
version '1.2.1'
ext{
mindistryVersion = "v104"
// mindistryVersion = "-SNAPSHOT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ object Helper {
.replace("[red]", ColorCodes.LIGHT_RED)
.replace("[yellow]", ColorCodes.YELLOW)
.replace("[white]", ColorCodes.WHITE)
.replace("[blue]", ColorCodes.LIGHT_BLUE)
.replace("[]", ColorCodes.RESET)
Log.info(replaced)
}
Expand All @@ -110,14 +111,16 @@ object Helper {
fun nextMap(map: Map? = null,mode: Gamemode = Gamemode.survival): Map {
val maps = Config.maps.copy()
maps.shuffle()
return maps.filter { bestMode(it)==mode}.first { it != map } ?: maps[0]
return maps.filter { bestMode(it) == mode }.firstOrNull { it != map } ?: maps[0]
}

fun bestMode(map: Map): Gamemode {
return when (map.file.name()[0]) {
'A' -> Gamemode.attack
'P' -> Gamemode.pvp
'S' -> Gamemode.survival
'C' -> Gamemode.sandbox
'E' -> Gamemode.editor
else -> Gamemode.bestFit(map.rules())
}
}
Expand Down
37 changes: 26 additions & 11 deletions MindustryPlugin/src/main/kotlin/cf/wayzer/mindustry/Listener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import mindustry.Vars
import mindustry.content.Blocks
import mindustry.entities.type.Player
import mindustry.game.EventType
import mindustry.game.Gamemode
import mindustry.game.Team
import mindustry.gen.Call
import mindustry.net.Packets
Expand Down Expand Up @@ -77,21 +78,23 @@ object Listener {
Helper.logToConsole("&lcGame over! Reached wave &ly${Vars.state.wave}&lc with &ly${Vars.playerGroup.size()}&lc players online on map &ly${Vars.world.map.name()}&lc.")

val map = Helper.nextMap(Vars.world.map)
Call.onInfoMessage("""
val msg = """
| ${if (Vars.state.rules.pvp) "[YELLOW] ${e.winner.name} 队胜利![]" else "[SCARLET]游戏结束![]"}
| 下一张地图为:[accent]${map.name()}[] By: [accent]${map.author()}[]
| 下一场游戏将在 ${Config.base.waitingTime.seconds} 秒后开始
""".trimMargin())
""".trimMargin()
Call.onInfoMessage(msg)
Helper.broadcast(msg, true)
Helper.logToConsole("Next map is ${map.name()}")
Main.timer.schedule(Config.base.waitingTime.toMillis()) {
Helper.loadMap(map)
}
//TODO 结算经验 And 排行榜系统
RuntimeData.calTime()
RuntimeData.gameTime.filter { it.value < 5000 }.forEach{
RuntimeData.gameTime.filter { it.value < 5000 }.forEach {
RuntimeData.gameTime.remove(it.key) //Remove less than 5 second
}
if(Vars.state.rules.pvp){
if (Vars.state.rules.pvp) {
//Remove loss Team
RuntimeData.gameTime.keys.filter { e.winner != RuntimeData.teams[it] }.forEach{
RuntimeData.gameTime.remove(it)
Expand All @@ -102,23 +105,35 @@ object Listener {
builder.append("[yellow]总贡献时长: "+all/1000/60+"分钟\n")
builder.append("[yellow]贡献度排名(目前根据时间): ")
RuntimeData.gameTime.entries.sortedByDescending { it.value }.joinTo(builder) {
val percent = String.format("%.2f",(it.value / all*100))
val percent = String.format("%.2f", (it.value / all * 100))
"[]" + playerData[it.key]!!.lastName + "[]([red]$percent%[])"
}
Helper.broadcast(builder.toString())
}
Events.on(EventType.PlayerBanEvent::class.java){e->
//Kick player when banned
Events.on(EventType.PlayerBanEvent::class.java) { e ->
e.player?.info?.lastKicked = Time.millis()
e.player?.con?.kick(Packets.KickReason.banned)
}
Events.on(ValidateException::class.java){e->
//Quit PVP mode when no player
Events.on(EventType.PlayerLeave::class.java) { e ->
if (!Vars.state.rules.pvp) return@on
Core.app.post {
if (!Vars.playerGroup.isEmpty) return@post
val next = Helper.nextMap()
//Prevent only PVP server
if (Helper.bestMode(next) == Gamemode.pvp) return@post
Helper.loadMap(next)
}
}
Events.on(ValidateException::class.java) { e ->
Call.onWorldDataBegin(e.player.con)
Vars.netServer.sendWorldData(e.player)
e.player.sendMessage("[red]检验异常,自动同步")
}
//PVP Control
var t=0
Events.on(EventType.Trigger.update){
//PVP Protect
var t = 0
Events.on(EventType.Trigger.update) {
if (!RuntimeData.pvpProtect) return@on
t = (t + 1) % 180
if (t != 0) return@on //per 60ticks | 3 seconds
Expand Down Expand Up @@ -161,7 +176,7 @@ object Listener {
}
if (e.message.startsWith('!') || e.message.startsWith('\\'))
Core.app.post {
e.player.sendMessage("[yellow]本服插件为原创,请使用[red]/help[yellow]查看指令帮助")
e.player.sendMessage("[yellow]本服插件为原创,指令均为/开头,使用[red]/help[yellow]查看指令帮助")
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ Essitial plugin for Mindustry (now only Chinese,need English version open an iss
当前使用在我自己服务器 m.tiny:smile:lake.tk

## 功能介绍
1. 重写默认换图机制(可以根据文件名首字母确定模式 S生存P对抗A攻击)
1. 重写默认换图机制(可以根据文件名首字母确定模式 S生存P对抗A攻击C沙盒创造E编辑器模式)
2. 完整投票功能(跳波,换图,踢人,投降,回滚)
3. 每10分钟自动保存(整10, xx:00保存为100,xx:50保存为105)
4. 额外的管理员系统(可以执行管理员指令,vote kick立即执行)
5. 进服欢迎信息(目前为硬编码,如需修改,请修改源码并手动编译)
6. 开源,可直接修改配置(配置在[Config.kt](/~https://github.com/way-zer/MyMindustryPlugin/blob/master/MindustryPlugin/src/main/kotlin/cf/wayzer/mindustry/Config.kt)文件中)
6. 开源,~~可直接修改配置(配置在[Config.kt](/~https://github.com/way-zer/MyMindustryPlugin/blob/master/MindustryPlugin/src/main/kotlin/cf/wayzer/mindustry/Config.kt)文件中)~~(已有配置文件config/pluginConf.conf)
7. PVP辅助(PVP保护时间;防止重进换队等)
8. 贡献榜(一局结算一次,目前根据时间贡献,有更好的请联系我)
9. 限制每队单位数量(兵和无人机,防卡服)
Expand Down Expand Up @@ -47,6 +47,8 @@ Essitial plugin for Mindustry (now only Chinese,need English version open an iss
- 增加反捣乱措施
- 完善用户等级机制
- 直接地图评价机制
- 增加对沙盒和编辑器模式的支持
- 国际化支持(每个玩家单独语言)

### 更新日记及下载
请见[发布页](/~https://github.com/way-zer/MyMindustryPlugin/releases)
Expand Down

0 comments on commit ac6a897

Please sign in to comment.