Jump to content
Korean Random

Custom Script to calculate Wn8/WnX // Efficiency During Battle


Recommended Posts

I've been working on my own XVM configuration mod, but have hit a brick wall and I'm hoping for a bit of guidance or help on this part. I've been able to setup and configure a custom hitLog, damageLog and totalEfficiency panels, I'm in the process of working on a highCaliber panel and a WNX // Efficiency panel as well. I have the foundation in place for the WNX // EFF panel, but I'm not sure what the best way to go about calculating it is real time based on the values that it needs. I started off thinking I wanted Wn8, but realized WnX is probably the future and want to focus on that, but if there isn't enough there to do WnX, then Wn8 is fine for now.

 

I know on this website (https://tomato.gg/wnx) you can acquire the expected values .JSON file as well as see the implementation calculations and formulas (by clicking the Implementation tab). But, with just learning how to use XVM, it seems like it can be a bit finicky in terms of loading in custom scripts without accidentally pulling a __load_lib error. below I've attached my current script and I'd like to know how to proceed if someone has the patience to help. :)

 

    "skillCalc": {
      "$ref": { "path": "def.formatTemplate" },
      "enabled": true,
      "x": 450,
      "y": 0,
      "width": 300,
      "height": 250,
      "format": "<b>WNX</b>: <font color='{{c:wn8({{py:getWn8}})}}'>{{py:getWn8}}</font>  //  <b>EFF</b>: <font color='{{c:eff({{py:getEff}})}}'>{{py:getEff}}</font>"
    }

 

image.thumb.png.7a67257265bd4f01bdb374273533ca36.png

 

import BigWorld

# --- Globals ---
g_manager = None
g_initialized = False

# --- Manager Class ---
class LivePerformanceManager(object):
    def __init__(self):
        self.damage = 0
        self.frags = 0
        from xvm_battle.battle import g_battle
        g_battle.onShotResult += self.on_shot_result

    def destroy(self):
        from xvm_battle.battle import g_battle
        g_battle.onShotResult -= self.on_shot_result

    def on_shot_result(self, vehID, shot_damage, shot_flags, *args, **kwargs):
        if vehID == BigWorld.player().playerVehicleID:
            self.damage += shot_damage
            if shot_flags & 0x1: self.frags += 1

    def calculate_wn8(self):
        try:
            from xvm_main.vehinfo import g_vehinfo
            player = BigWorld.player()
            veh_id = player.vehicleTypeDescriptor.type.id
            expected = g_vehinfo.get_expected_values(veh_id)
            if not expected: return 0
            rDAMAGE = self.damage / expected['expDamage'] if expected['expDamage'] > 0 else 0
            rFRAG = self.frags / expected['expFrag'] if expected['expFrag'] > 0 else 0
            rWINc = 0.5
            cDAMAGE = max(0, (rDAMAGE - 0.22) / (1.0 - 0.22))
            cFRAG = max(0, min(cDAMAGE + 0.2, (rFRAG - 0.12) / (1.0 - 0.12)))
            wn8 = 980*cDAMAGE + 210*cDAMAGE*cFRAG + 155*cFRAG*0 + 75*0*cFRAG + 145*min(1.8, rWINc)
            return int(wn8)
        except: return 0

    def calculate_eff(self):
        try:
            player = BigWorld.player()
            tier = player.vehicleTypeDescriptor.level or 1
            eff = (self.damage * (10 / (tier + 2)) * (0.23 + 2 * tier / 100) + self.frags * 250)
            return int(eff)
        except: return 0

# --- Event Handlers ---
def on_battle_loaded(*args, **kwargs):
    global g_manager
    g_manager = LivePerformanceManager()

def on_battle_destroyed(*args, **kwargs):
    global g_manager
    if g_manager is not None:
        g_manager.destroy()
        g_manager = None

# --- Initialization Function ---
def initialize():
    global g_initialized
    if g_initialized: return
    g_initialized = True
    from xvm_battle.battle import g_battle
    g_battle.onBattleLoaded += on_battle_loaded
    g_battle.onBattleDestroy += on_battle_destroyed

# --- Public API Functions ---
@xvm.export('getWn8', deterministic=False)
def getWn8():
    initialize()
    if g_manager is not None:
        return g_manager.calculate_wn8()
    return 0

@xvm.export('getEff', deterministic=False)
def getEff():
    initialize()
    if g_manager is not None:
        return g_manager.calculate_eff()
    return 0

 

wnx-expected-values.json

 

 

 

Edited by RavenStryker
Link to comment
Short link
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...