313 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			313 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:FunctionalPack.nut
 | |
| 路径:User/Socket/FunctionalPack.nut
 | |
| 创建日期:2025-01-05	00:07
 | |
| 文件用途:功能数据包
 | |
| */
 | |
| 
 | |
| //注册功能包
 | |
| function RegisterFunctionalPack() {
 | |
|     // 选择角色进入游戏回包
 | |
|     MySocket.RegisterHandler(PACKET_ID.SELECT_CHARACTER_ENTER_GAME_CALLBACK, function(Jso) {
 | |
|         local Info = Jso.charac;
 | |
| 
 | |
|         //构造城镇
 | |
|         local TownObj = Town(Info.town);
 | |
| 
 | |
|         local Charc = GameObject.CreateCharacter(Info.job, [], true);
 | |
|         //构造角色
 | |
|         {
 | |
|             Charc.Cid = Info.cid;
 | |
|             Charc.GrowJob = Info.jobEx;
 | |
|             Charc.Level = Info.lv;
 | |
|             Charc.Exp = Info.exp;
 | |
|             Charc.Fatigue = Info.fatigue;
 | |
|             Charc.SkillPoint = Info.sp;
 | |
| 
 | |
|             Charc.SetName(Info.name);
 | |
|             Charc.InitAttr(); //初始化角色属性
 | |
|             TownObj.AddObject(Charc, true);
 | |
|             ClientCharacter = Charc;
 | |
|         }
 | |
| 
 | |
|         //以下是角色应当初始化的各项东西
 | |
|         {
 | |
|             //初始化背包
 | |
|             if (ClientCharacterInventory) {
 | |
|                 ClientCharacterInventory.DestroyWindow();
 | |
|             }
 | |
|             ClientCharacterInventory = UISpace_Inventory._Inventory("背包窗口", 634, 20, 262, 548, 20);
 | |
| 
 | |
|             //初始化个人信息
 | |
|             if (ClientPersonalInfo) {
 | |
|                 ClientPersonalInfo.DestroyWindow();
 | |
|             }
 | |
|             ClientPersonalInfo = UISpace_PersonalInfo._PersonalInfo("个人信息窗口", 150, 35, 286, 530, 20);
 | |
| 
 | |
|             //初始化HUD
 | |
|             if (ClientHUD) {
 | |
|                 ClientHUD.DestroyWindow();
 | |
|             }
 | |
|             ClientHUD = UISpace_Hud._Hud();
 | |
|             ClientHUD.ResetFocus();
 | |
| 
 | |
|             //初始化技能树
 | |
|             if (ClientSkillTreeWindow) {
 | |
|                 ClientSkillTreeWindow.DestroyWindow();
 | |
|             }
 | |
|             ClientSkillTreeWindow = UISpace_SkillTree._SkillTree("技能树窗口", 135, 4, 796, 524, 20);
 | |
|             ClientSkillTreeWindow.Init(Charc.Job, Charc.GrowJob);
 | |
|             ClientSkillTreeWindow.ResetFocus();
 | |
|         }
 | |
|     });
 | |
| 
 | |
|     //刷新客户端角色背包数据
 | |
|     MySocket.RegisterBinaryHandler(PACKET_ID.REFRESH_CLIENT_CHARACTER_INVENTORY_DATA_CALLBACK, function(Binary) {
 | |
|         local Pack = Packet(Binary);
 | |
|         local op = Pack.Get_Int();
 | |
|         //背包大小
 | |
|         local InventorySize = Pack.Get_Int();
 | |
|         //背包类型
 | |
|         local InventoryType = Pack.Get_Byte();
 | |
|         //背包道具数量
 | |
|         local InventoryItemCount = Pack.Get_Short();
 | |
| 
 | |
|         //项目List
 | |
|         local ItemList = {};
 | |
| 
 | |
|         //道具数据
 | |
|         for (local i = 0; i< InventoryItemCount; i++) {
 | |
|             local ItemStruct = GameItem.Item.ConstructionItemByPacket(Pack);
 | |
|             ItemList[ItemStruct.Pos] <- ItemStruct.Item;
 | |
|         }
 | |
| 
 | |
|         //穿戴栏
 | |
|         if (InventoryType == 1) {
 | |
|             foreach(Index, EquObj in ItemList) {
 | |
|                 ClientCharacterInventory.PageList[0].CharactersObject.SetEquipment(Index, EquObj);
 | |
|                 //给角色赋予穿戴装备
 | |
|                 if (EquObj) {
 | |
|                     ClientCharacter.WearEquipment(EquObj);
 | |
|                 }
 | |
|             }
 | |
|             //处理完穿戴装备以后,重新计算角色属性
 | |
|             ClientCharacter.ReadFullEquipAttr();
 | |
|             //刷新一下个人信息
 | |
|             ClientPersonalInfo.RefreshPersonalInfo();
 | |
|         }
 | |
|         //背包栏
 | |
|         else if (InventoryType > 1 && InventoryType< 7) {
 | |
|             ClientCharacterInventory.PageList[0].SetItemCollectionList(InventoryType - 2, ItemList);
 | |
|         }
 | |
|         //时装穿戴栏
 | |
|         else if (InventoryType == 8) {
 | |
|             foreach(Index, EquObj in ItemList) {
 | |
|                 ClientCharacterInventory.PageList[1].CharactersObject.SetEquipment(Index, EquObj);
 | |
|                 //给角色赋予穿戴装备
 | |
|                 if (EquObj) {
 | |
|                     ClientCharacter.WearEquipment(EquObj);
 | |
|                 }
 | |
|             }
 | |
|             //刷新背包中的人物Ani
 | |
|             ClientCharacterInventory.RefreshRoleAni();
 | |
|             //刷新一下个人信息
 | |
|             ClientPersonalInfo.RefreshPersonalInfo();
 | |
|         }
 | |
|         //时装
 | |
|         else if (InventoryType == 9) {
 | |
|             ClientCharacterInventory.PageList[1].SetItemCollectionList(InventoryType - 9, ItemList);
 | |
|         }
 | |
|     });
 | |
| 
 | |
|     //刷新客户端角色背包单个槽数据
 | |
|     MySocket.RegisterBinaryHandler(PACKET_ID.INVENTORY_ADD_ITEM_CALLBACK, function(Binary) {
 | |
|         local Pack = Packet(Binary);
 | |
|         local op = Pack.Get_Int();
 | |
|         local InventoryType = Pack.Get_Byte(); //背包类型
 | |
|         local ItemStruct = GameItem.Item.ConstructionItemByPacket(Pack);
 | |
|         //穿戴栏
 | |
|         if (InventoryType == 1) {
 | |
|             ClientCharacterInventory.PageList[0].CharactersObject.SetEquipment(ItemStruct.Pos, ItemStruct.Item);
 | |
|         }
 | |
|         //背包栏
 | |
|         else if (InventoryType > 1 && InventoryType< 7) {
 | |
|             ClientCharacterInventory.PageList[0].SetItemCollectionSlot(InventoryType - 2, ItemStruct.Pos, ItemStruct.Item);
 | |
|         }
 | |
|         //时装
 | |
|         else if (InventoryType == 9) {
 | |
|             ClientCharacterInventory.PageList[1].SetItemCollectionSlot(InventoryType - 9, ItemStruct.Pos, ItemStruct.Item);
 | |
|         }
 | |
|     });
 | |
|     MySocket.RegisterBinaryHandler(PACKET_ID.INVENTORY_REMOVE_ITEM_CALLBACK, function(Binary) {
 | |
|         local Pack = Packet(Binary);
 | |
|         local op = Pack.Get_Int();
 | |
|         local InventoryType = Pack.Get_Byte(); //背包类型
 | |
|         local Pos = Pack.Get_Short();
 | |
|         //穿戴栏
 | |
|         if (InventoryType == 1) {
 | |
|             ClientCharacterInventory.PageList[0].CharactersObject.SetEquipment(Pos, null);
 | |
|         }
 | |
|         //背包栏
 | |
|         else if (InventoryType > 1 && InventoryType< 7) {
 | |
|             ClientCharacterInventory.PageList[0].SetItemCollectionSlot(InventoryType - 2, Pos, null);
 | |
|         }
 | |
|         //时装
 | |
|         else if (InventoryType == 9) {
 | |
|             ClientCharacterInventory.PageList[1].SetItemCollectionSlot(InventoryType - 9, Pos, null);
 | |
|         }
 | |
|     });
 | |
|     //穿戴装备的回包
 | |
|     MySocket.RegisterHandler(PACKET_ID.WEAR_EQUIPMENT_CALLBACK, function(Jso) {
 | |
|         //页面ID
 | |
|         local PageId = 0;
 | |
|         local OldBackpackId = Jso.oldbackpackId;
 | |
|         local OldPos = Jso.oldpos;
 | |
|         local NewBackpackId = Jso.newbackpackId;
 | |
|         //时装页面1
 | |
|         if (NewBackpackId == 9) {
 | |
|             PageId = 1;
 | |
|             NewBackpackId = 0
 | |
|         }
 | |
|         //装备页面0
 | |
|         else {
 | |
|             NewBackpackId -= 2
 | |
|         }
 | |
|         local NewPos = Jso.newpos;
 | |
| 
 | |
|         local OldItem = null;
 | |
|         local NewItem = null;
 | |
|         if (OldBackpackId) {
 | |
|             OldItem = ClientCharacterInventory.PageList[PageId].CharactersObject.EquipmentSlot[OldPos].Item;
 | |
|             ClientCharacter.UnWearEquipment(OldItem);
 | |
|         }
 | |
|         //背包位置可能无装备
 | |
|         if (ClientCharacterInventory.PageList[PageId].ItemCollectionList[NewBackpackId].ItemList[NewPos]) {
 | |
|             NewItem = ClientCharacterInventory.PageList[PageId].ItemCollectionList[NewBackpackId].ItemList[NewPos].Item;
 | |
|             ClientCharacter.WearEquipment(ClientCharacterInventory.PageList[PageId].ItemCollectionList[NewBackpackId].ItemList[NewPos].Item);
 | |
|         }
 | |
| 
 | |
|         //设置背包槽里的Item  如果原先有装备就设置那件 如果原先没有 则设置为null
 | |
|         ClientCharacterInventory.PageList[PageId].SetItemCollectionSlot(NewBackpackId, NewPos, OldItem);
 | |
|         //设置角色装备栏里的Item
 | |
|         ClientCharacterInventory.PageList[PageId].CharactersObject.SetEquipment(OldPos, NewItem);
 | |
|         //设置个人信息栏里的装备Item
 | |
|         if (PageId == 0) ClientPersonalInfo.PageList[PageId].CharactersObject.SetEquipment(OldPos, NewItem);
 | |
|         //刷新背包中的人物Ani
 | |
|         ClientCharacterInventory.RefreshRoleAni();
 | |
|         //处理完穿戴装备以后,重新计算角色属性
 | |
|         if (OldItem && PageId == 0) ClientCharacter.Attr -= OldItem.Attr;
 | |
|         if (NewItem && PageId == 0) ClientCharacter.Attr += NewItem.Attr;
 | |
|         //刷新一下个人信息
 | |
|         ClientPersonalInfo.RefreshPersonalInfo();
 | |
|     });
 | |
| 
 | |
|     //刷新客户端角色背包点卷代币券信息
 | |
|     MySocket.RegisterHandler(PACKET_ID.REFRESH_CLIENT_CHARACTER_CERA_DATA_CALLBACK, function(Jso) {
 | |
|         ClientCharacterInventory.WalletSet("Cera", Jso.coupon);
 | |
|     });
 | |
| 
 | |
|     //刷新客户端角色背包金币信息
 | |
|     MySocket.RegisterHandler(PACKET_ID.REFRESH_CLIENT_CHARACTER_GOLD_DATA_CALLBACK, function(Jso) {
 | |
|         ClientCharacterInventory.WalletSet("Gold", Jso.gold);
 | |
|     });
 | |
| 
 | |
|     //刷新客户端角色背包复活币信息
 | |
|     MySocket.RegisterHandler(PACKET_ID.REFRESH_CLIENT_CHARACTER_REVIVE_DATA_CALLBACK, function(Jso) {
 | |
|         ClientCharacterInventory.WalletSet("ReviveCoin", Jso.revive);
 | |
|     });
 | |
| 
 | |
| 
 | |
|     //城镇中添加角色的回包
 | |
|     MySocket.RegisterBinaryHandler(PACKET_ID.TOWN_ADD_CHARACTER_CALLBACK, function(Binary) {
 | |
|         local Pack = Packet(Binary);
 | |
|         local op = Pack.Get_Int();
 | |
|         local cid = Pack.Get_Int();
 | |
|         local namelen = Pack.Get_Byte();
 | |
|         local name = Pack.Get_String(namelen);
 | |
|         local job = Pack.Get_Byte();
 | |
|         local lv = Pack.Get_Byte();
 | |
|         local moveflag = Pack.Get_Byte();
 | |
|         local posx = Pack.Get_Int();
 | |
|         local posy = Pack.Get_Int();
 | |
|         local posz = 0;
 | |
|         local equcount = Pack.Get_Byte();
 | |
|         local equ = [];
 | |
|         for (local i = 0; i< equcount; i++) {
 | |
|             equ.push(Pack.Get_Int());
 | |
|         }
 | |
|         //构造角色
 | |
|         local Charc = GameObject.CreateCharacter(job, equ);
 | |
|         Charc.Cid = cid;
 | |
|         Charc.SetName(name);
 | |
|         Charc.SetPosition(posx, posy, posz);
 | |
|         //从全局地图中找到城镇并添加角色
 | |
|         if (GlobalTownManager.CurrentMap) {
 | |
|             GlobalTownManager.CurrentMap.AddObject(Charc);
 | |
|         }
 | |
| 
 | |
|         //设置角色移动状态
 | |
|         if (moveflag != DIRECTION.NONE) {
 | |
|             Charc.SetMoveFlag(moveflag);
 | |
|         }
 | |
| 
 | |
|     });
 | |
| 
 | |
|     //城镇中移除角色的回包
 | |
|     MySocket.RegisterHandler(PACKET_ID.TOWN_REMOVE_CHARACTER_CALLBACK, function(Jso) {
 | |
|         //从全局地图中找到城镇并移除角色
 | |
|         if (GlobalTownManager.CurrentMap) {
 | |
|             //遍历所有角色
 | |
|             foreach(obj in GlobalTownManager.CurrentMap.PlayerList) {
 | |
|                 //角色对象
 | |
|                 if (typeof obj == "Game_Character" && obj.Cid == Jso.cid) {
 | |
|                     GlobalTownManager.CurrentMap.RemoveObject(obj);
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|     });
 | |
| 
 | |
|     //移动城镇的回包
 | |
|     MySocket.RegisterHandler(PACKET_ID.CHANGE_TOWN_AREA_CALLBACK, function(Jso) {
 | |
|         //我自己的移动城镇添加角色对象
 | |
|         local MapObj = GlobalTownManager.TownList[Jso.town].map[Jso.region];
 | |
|         MapObj.AddObjectByChangeTown(ClientCharacter, Jso.pos);
 | |
|     });
 | |
| 
 | |
|     //城镇中角色移动的回包
 | |
|     MySocket.RegisterBinaryHandler(PACKET_ID.TOWN_CHARACTER_MOVE_CALLBACK, function(Binary) {
 | |
|         local Pack = Packet(Binary);
 | |
|         Pack.Get_Int();
 | |
|         local cid = Pack.Get_Int();
 | |
|         local MoveFlag = Pack.Get_Byte();
 | |
|         local X = Pack.Get_Int();
 | |
|         local Y = Pack.Get_Int();
 | |
|         //获取角色对象
 | |
|         local obj = GameObject.GetCharacterByCid(cid);
 | |
|         if (obj) {
 | |
|             obj.SetPosition(X, Y, 0);
 | |
|             obj.SetMoveFlag(MoveFlag);
 | |
|         }
 | |
|     });
 | |
| 
 | |
| 
 | |
|     //注册聊天信息收包
 | |
|     MySocket.RegisterHandler(PACKET_ID.SEND_CHAT_MESSAGE_CALLBACK, function(Jso) {
 | |
|         ClientChatWindow.PushMsg(Jso);
 | |
| 
 | |
|         //获取角色对象
 | |
|         local obj = GameObject.GetCharacterByCid(Jso.cid);
 | |
|         if (obj) obj.SetChatBubble(Jso.msg);
 | |
|     }.bindenv(this));
 | |
| }
 | |
| 
 | |
| //城镇包
 | |
| TOWN_PACKET <- {
 | |
|     //城镇角色移动改变状态包
 | |
|     function SendTownMoveStatePacket(X, Y, MoveFlag) {
 | |
|         local Pack = Packet();
 | |
|         Pack.Put_Byte(MoveFlag);
 | |
|         Pack.Put_Int(X);
 | |
|         Pack.Put_Int(Y);
 | |
|         MySocket.Send(PACKET_ID.TOWN_CHARACTER_MOVE, Pack.Data);
 | |
|     }
 | |
| } |