Code:
#! /usr/bin/env python
import app, dbg, chr, chrmgr, os, introSelect
"""
Render Monster Card
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A simple Python Module which gives you the chance to be able to turn mob differently with a specific animation such as atack, motion, death etc.
This module was not designed for beginners in python, this is just a beginning for the rendering of every monster.
You can also use it for other systems for render.
WARNING:
I don't offer any support for this, that module is just for guys who know what have to do.
Code isn't working like official one.
This script has not been tested, is just a simple idea like better then 'pseudocode',
you need to improve and do compatible with your scripts.
Copyright: (c) 2016 VegaS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""
class RenderMonsterCardParser():
def __init__(self):
self.monsterCardDict = GetMonsterCardPaths()
self.srcFileName = 'monster_card.txt'
self.startInstanceIndex = 90000
self.destRotation = 25.0
self.renderPos = {
'x': 70.0,
'y': 22.0,
'z': 30.0
}
self.chrRenderer = introSelect.SelectCharacterWindow().CharacterRenderer()
self.chrRenderer.SetParent(self)
self.chrRenderer.Show()
def GetMonsterCardPaths(self):
m2dict = {'pathName': '','raceData': ''}
try:
lines = pack_open(self.srcFileName, "r").readlines()
except IOError:
dbg.LogBox("Can't load: {0}".format(self.srcFileName))
app.Abort()
for (key, value) in enumerate(lines):
data = value[:-1].split(",")
if (not len(data) or not data[0] or not data[1]):
continue
m2dict.update({key : {'pathName': data[0].strip(), 'raceData': data[1].strip()}})
return m2dict
def RegisterDefaultMotion(self):
chrmgr.RegisterMotionMode(chr.MOTION_MODE_GENERAL)
chrmgr.RegisterMotionData(chr.MOTION_MODE_GENERAL, chr.MOTION_WAIT, 'wait.msa')
chrmgr.RegisterMotionData(chr.MOTION_MODE_GENERAL, chr.MOTION_RUN, 'wait2.msa')
def OnUpdate(self):
chr.Update()
self.destRotation -= 0.5
chr.SetRotation(self.destRotation)
def OnRender(self, slotIndex):
def CreateMonsterInstance(slotIndex):
chrmgr.CreateRace(slotIndex)
chrmgr.SelectRace(slotIndex)
chrmgr.SetPathName(self.monsterCardDict[slotIndex]['pathName'])
chrmgr.LoadRaceData(self.monsterCardDict[slotIndex]['raceData'])
CreateMonsterInstance(slotIndex)
chrEventDict = {
0 : (lambda : chr.CreateInstance(slotIndex)),
1 : (lambda : chr.SelectInstance(slotIndex)),
2 : (lambda : chr.SetVirtualID(slotIndex)),
3 : (lambda : chr.SetRace(slotIndex)),
4 : (lambda : chr.SetArmor(0)),
5 : (lambda : chr.SetRotation(self.destRotation)),
6 : (lambda : chr.SetPixelPosition(self.renderPos['x'], self.renderPos['y'], self.renderPos['z'])),
7 : (lambda : chr.SetMotionMode(chr.MOTION_MODE_GENERAL)),
8 : (lambda : chr.SetLoopMotion(chr.MOTION_WAIT)),
9 : (lambda : chr.Refresh()),
10 : (lambda : chr.Show())
}
[chrEventDict.get(chrObject, lambda *arg: None)() for chrObject in chrEventDict.values()]
def OnChangeMotionData(self, motionMode = chr.MOTION_MODE_GENERAL, motionType = chr.MOTION_COMBO_ATTACK_1, motionPathName = '', motionWeight = 0)
chrmgr.RegisterMotionData(motionMode, motionType, motionPathName, motionWeight)
def OnRenderMonsterCard(self, slotIndex):
def ClearInstance(max_range_num):
[chr.DeleteInstance(self.startInstanceIndex + rangeInst) for rangeInst in xrange(max_range_num)]
if (not self.monsterCardDict.has_key(slotIndex)):
return
ClearInstance(len(self.monsterCardDict[0]))
self.RegisterDefaultMotion()
self.OnRender(self.startInstanceIndex + slotIndex)







