VegaS1234

[Python] Class Render Monster Card

Nov 25th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.60 KB | None | 0 0
  1. #! /usr/bin/env python
  2. import app, dbg, chr, chrmgr, os, introSelect
  3.  
  4. """
  5.    Render Monster Card
  6.    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7.     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.
  8.     This module was not designed for beginners in python, this is just a beginning for the rendering of every monster.
  9.     You can also use it for other systems for render.
  10.    
  11.     WARNING:
  12.         I don't offer any support for this.
  13.         Code isn't working like official one.
  14.         This script has not been tested, is just a simple idea like better then 'pseudocode',
  15.         you need to improve and do compatible with your scripts.
  16.  
  17.     Copyright: (c) 2016 VegaS
  18.     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. """
  20.  
  21. class RenderMonsterCardParser():
  22.     def __init__(self):
  23.         self.monsterCardDict = GetMonsterCardPaths()
  24.         self.srcFileName = 'monster_card.txt'
  25.         self.startInstanceIndex = 90000
  26.         self.destRotation = 25.0
  27.         self.renderPos = {
  28.             'x': 70.0,
  29.             'y': 22.0,
  30.             'z': 30.0
  31.         }
  32.        
  33.         self.chrRenderer = introSelect.SelectCharacterWindow().CharacterRenderer()
  34.         self.chrRenderer.SetParent(self)
  35.         self.chrRenderer.Show()
  36.        
  37.     def GetMonsterCardPaths(self):
  38.         m2dict = {'pathName': '','raceData': ''}
  39.         try:
  40.             lines = pack_open(self.srcFileName, "r").readlines()
  41.         except IOError:
  42.             dbg.LogBox("Can't load: {0}".format(self.srcFileName))
  43.             app.Abort()
  44.  
  45.         for (key, value) in enumerate(lines):
  46.             data = value[:-1].split(",")
  47.  
  48.             if (not len(data) or not data[0] or not data[1]):
  49.                 continue
  50.  
  51.             m2dict.update({key : {'pathName': data[0].strip(), 'raceData': data[1].strip()}})
  52.            
  53.         return m2dict
  54.        
  55.     def RegisterDefaultMotion(self):
  56.         chrmgr.RegisterMotionMode(chr.MOTION_MODE_GENERAL)
  57.         chrmgr.RegisterMotionData(chr.MOTION_MODE_GENERAL, chr.MOTION_WAIT, 'wait.msa')
  58.         chrmgr.RegisterMotionData(chr.MOTION_MODE_GENERAL, chr.MOTION_RUN, 'wait2.msa')
  59.        
  60.     def OnUpdate(self):
  61.         chr.Update()
  62.         self.destRotation = -= 0.5
  63.         chr.SetRotation(self.destRotation)
  64.  
  65.     def OnRender(self, slotIndex):
  66.  
  67.         def CreateMonsterInstance(slotIndex):
  68.             chrmgr.CreateRace(slotIndex)
  69.             chrmgr.SelectRace(slotIndex)
  70.             chrmgr.SetPathName(self.monsterCardDict[slotIndex]['pathName'])
  71.             chrmgr.LoadRaceData(self.monsterCardDict[slotIndex]['raceData'])
  72.  
  73.         CreateMonsterInstance(slotIndex)
  74.  
  75.         chrEventDict = {
  76.             0 : (lambda : chr.CreateInstance(slotIndex)),
  77.             1 : (lambda : chr.SelectInstance(slotIndex)),
  78.             2 : (lambda : chr.SetVirtualID(slotIndex)),
  79.             3 : (lambda : chr.SetRace(slotIndex)),
  80.             4 : (lambda : chr.SetArmor(0)),
  81.             5 : (lambda : chr.SetRotation(self.destRotation)),
  82.             6 : (lambda : chr.SetPixelPosition(self.renderPos['x'], self.renderPos['y'], self.renderPos['z'])),
  83.             7 : (lambda : chr.SetMotionMode(chr.MOTION_MODE_GENERAL)),
  84.             8 : (lambda : chr.SetLoopMotion(chr.MOTION_WAIT)),
  85.             9 : (lambda : chr.Refresh()),
  86.             10 : (lambda : chr.Show())
  87.         }
  88.        
  89.         [chrEventDict.get(chrObject, lambda *arg: None)() for chrObject in chrEventDict.values()]
  90.        
  91.     def OnChangeMotionData(self, motionMode = chr.MOTION_MODE_GENERAL, motionType = chr.MOTION_COMBO_ATTACK_1, motionPathName = '', motionWeight = 0)
  92.         chrmgr.RegisterMotionData(motionMode, motionType, motionPathName, motionWeight)
  93.  
  94.     def OnRenderMonsterCard(self, slotIndex):
  95.         def ClearInstance(max_range_num):
  96.             [chr.DeleteInstance(self.startInstanceIndex + rangeInst) for rangeInst in xrange(max_range_num)]
  97.  
  98.         if (not self.monsterCardDict.has_key(slotIndex)):
  99.             return
  100.  
  101.         ClearInstance(len(self.monsterCardDict[0]))
  102.         self.RegisterDefaultMotion()
  103.         self.OnRender(self.startInstanceIndex + slotIndex)
Advertisement
Add Comment
Please, Sign In to add comment