Files
metin2-client/src/platform/ScriptLib/ServerBonusScript.inc
T

108 lines
3.0 KiB
PHP

// PORT: server rates and privilege events are not character AFFECT packets in 40250.
// Add distinct entries to the original affect bar; leave packed scripts unchanged.
static const char c_szServerBonusScript[] = R"PY(# -*- coding: utf-8 -*-
import app
import game
import net
import player
import ui
import uiAffectShower
L = player.AutoHuntLocalize
PREFIX = "d:/ymir work/ui/skill/common/affect/"
ENTRIES = (
("服务器经验 %d%%", "exp_bonus.sub", 100),
("服务器金币数量 %d%%", "gold_bonus.sub", 100),
("服务器金币掉落率 %d%%", "gold_bonus.sub", 100),
("服务器物品掉落率 %d%%", "item_bonus.sub", 100),
("活动经验加成 %+d%%", "exp_bonus.sub", 0),
("活动物品掉落加成 %+d%%", "item_bonus.sub", 0),
("活动金币掉落加成 %+d%%", "gold_bonus.sub", 0),
("活动金币礼包掉落加成 %+d%%", "gold_premium.sub", 0),
)
KEY_START = 20000
g_game = None
g_ticker = None
def Update(window, *values):
if len(values) != len(ENTRIES):
return
try:
values = tuple(int(value) for value in values)
except (ValueError, TypeError):
return
bar = window.affectShower
if not bar:
return
for i, ((text, asset, baseline), value) in enumerate(zip(ENTRIES, values)):
key = KEY_START + i
image = bar.affectImageDict.get(key)
if value == baseline:
if image:
image.Hide()
del bar.affectImageDict[key]
continue
if not image:
image = uiAffectShower.AffectImage()
image.SetParent(bar)
image.LoadImage(PREFIX + asset)
image.SetScale(0.7, 0.7)
image.SetAffect(key)
image.SetSkillAffectFlag(False)
image.SetClock(False)
bar.affectImageDict[key] = image
image.SetDescription(L(text % value))
image.UpdateDescription()
image.Show()
bar._AffectShower__ArrangeImageList()
class Ticker(ui.Window):
def __init__(self, window):
ui.Window.__init__(self)
self.window = window
self.nextQuery = app.GetTime() + 3.0
self.Show()
def OnUpdate(self):
now = app.GetTime()
if self.window and now >= self.nextQuery:
self.nextQuery = now + 15.0
net.SendChatPacket("/server_bonuses")
_open = game.GameWindow.Open
_close = game.GameWindow.Close
_command = game.GameWindow.BINARY_ServerCommand_Run
def Open(self):
global g_game, g_ticker
_open(self)
g_game = self
g_ticker = Ticker(self)
def Close(self):
global g_game, g_ticker
if g_ticker:
g_ticker.Hide()
g_ticker.window = None
g_game = g_ticker = None
_close(self)
def Command(self, line):
words = line.split()
if words and words[0] == "ServerBonuses":
Update(self, *words[1:])
return 1
return _command(self, line)
game.GameWindow.Open = Open
game.GameWindow.Close = Close
game.GameWindow.BINARY_ServerCommand_Run = Command
)PY";