56 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:PassiveObjectClass.nut
 | |
| 路径:User/GameClass/ObjectClass/PassiveObjectClass.nut
 | |
| 创建日期:2024-05-11	09:14
 | |
| 文件用途:被动对象
 | |
| */
 | |
| class PassiveObject extends ActiveObject {
 | |
| 
 | |
|     OnCreateFunction = null;
 | |
|     OnProcFunction = null;
 | |
|     OnDestroyFunction = null;
 | |
|     OnAttackFunction = null;
 | |
| 
 | |
|     function Init(Idx) {
 | |
|         Info = ScriptData.GetPassiveObject(Idx);
 | |
| 
 | |
|         base.Init(Info);
 | |
| 
 | |
|         //储存图层信息
 | |
|         if ("layer" in Info)
 | |
|             Layer = Info.layer.slice(1, -1);
 | |
| 
 | |
| 
 | |
|         //初始化回调函数
 | |
|         InitCallBackFunc();
 | |
|     }
 | |
| 
 | |
|     function InitCallBackFunc() {
 | |
|         if ("create function" in Info) OnCreateFunction = Info["create function"].bindenv(this);
 | |
|         if ("destroy function" in Info) OnDestroyFunction = Info["destroy function"].bindenv(this);
 | |
|         if ("proc function" in Info) OnProcFunction = Info["proc function"].bindenv(this);
 | |
|         if ("attack function" in Info) OnAttackFunction = Info["attack function"].bindenv(this);
 | |
|     }
 | |
| 
 | |
|     function OnAddchild(Parent) {
 | |
|         if (OnCreateFunction) OnCreateFunction(Parent);
 | |
|         base.OnAddchild(Parent);
 | |
|     }
 | |
| 
 | |
|     function OnRemove(Parent) {
 | |
|         if (OnDestroyFunction) OnDestroyFunction(Parent);
 | |
|         base.OnRemove(Parent);
 | |
|     }
 | |
| 
 | |
|     //攻击到其他对象时
 | |
|     function OnAttack(Damager) {
 | |
|         if (OnAttackFunction) OnAttackFunction(Damager);
 | |
|         base.OnAttack(Damager);
 | |
|     }
 | |
| 
 | |
|     //被调用
 | |
|     function OnUpdate(dt) {
 | |
|         if (OnProcFunction) OnProcFunction(dt);
 | |
|         base.OnUpdate(dt);
 | |
|     }
 | |
| } |