267 lines
		
	
	
		
			8.3 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			267 lines
		
	
	
		
			8.3 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:WorldClass.nut
 | |
| 路径:BaseClass/WorldClass/WorldClass.nut
 | |
| 创建日期:2024-04-07	21:25
 | |
| 文件用途:游戏世界类
 | |
| */
 | |
| class World {
 | |
|     constructor() {}
 | |
|     // 根据UID获取Session
 | |
|     function GetSessionByUid(Uid) {
 | |
|         return Sq_GameWorld_GetSessionByUid(Sq_Get_GameWorld(), Uid);
 | |
|     }
 | |
|     // 根据Session获取玩家
 | |
|     function GetUserBySession(Session) {
 | |
|         local CUser = Sq_GameWorld_GetUserBySession(Sq_Get_GameWorld(), Session);
 | |
|         if (CUser)
 | |
|             return User(CUser);
 | |
|         else
 | |
|             return null;
 | |
|     }
 | |
|     // 根据UID获取玩家
 | |
|     function GetUserByUid(Uid) {
 | |
|         local CUser = Sq_GameWorld_GetUserByUid(Sq_Get_GameWorld(), Uid);
 | |
|         if (CUser)
 | |
|             return User(CUser);
 | |
|         else
 | |
|             return null;
 | |
|     }
 | |
|     // 根据名字获取玩家
 | |
|     function GetUserByName(Name) {
 | |
|         local CUser = Sq_GameWorld_GetUserByName(Sq_Get_GameWorld(), Name);
 | |
|         if (CUser)
 | |
|             return User(CUser);
 | |
|         else
 | |
|             return null;
 | |
|     }
 | |
|     // 获取玩家数量
 | |
|     function GetUserCount() {
 | |
|         return Sq_GameWorld_GetUserCount(Sq_Get_GameWorld());
 | |
|     }
 | |
|     // 给所有玩家发包
 | |
|     function SendAll(Pack) {
 | |
|         Sq_GameWorld_SendAll(Sq_Get_GameWorld(), Pack.C_Object);
 | |
|     }
 | |
|     // 给所有玩家发送公告
 | |
|     function SendNotiPacketMessage(String, Type) {
 | |
|         local Pack = Packet();
 | |
|         Pack.Put_Header(0, 12);
 | |
|         Pack.Put_Byte(Type);
 | |
|         Pack.Put_Short(0);
 | |
|         Pack.Put_Byte(0);
 | |
|         Pack.Put_Int(String.len());
 | |
|         Pack.Put_Binary(String);
 | |
|         Pack.Finalize(true);
 | |
|         World.SendAll(Pack)
 | |
|         Pack.Delete();
 | |
|     }
 | |
| 
 | |
|     //发送公告消息  字符串数组
 | |
|     function SendNotiForColorPacketMessage(StringArr, Type) {
 | |
| 
 | |
|         local ColorArr = [];
 | |
|         local SendStrBlob = blob(1);
 | |
|         SendStrBlob.writen(0xc2, 'c');
 | |
|         SendStrBlob.writen(0x80, 'c');
 | |
|         foreach(sobj in StringArr) {
 | |
|             local StrPoint = Str_Ptr(sobj[0]);
 | |
|             local StrPointB = Sq_Point2Blob(StrPoint, sobj[0].len());
 | |
|             if (sobj[1]) {
 | |
|                 SendStrBlob.writen(0xc2, 'c');
 | |
|                 SendStrBlob.writen(0x80, 'c');
 | |
|                 SendStrBlob.writeblob(StrPointB);
 | |
|                 SendStrBlob.writen(0xc2, 'c');
 | |
|                 SendStrBlob.writen(0x80, 'c');
 | |
| 
 | |
|                 local ColorBlob = blob(104);
 | |
|                 for (local i = 0; i< 3; i++) {
 | |
|                     ColorBlob.writen(sobj[2][i], 'c');
 | |
|                 }
 | |
|                 for (local i = 0; i< 101; i++) {
 | |
|                     ColorBlob.writen(0xff, 'c');
 | |
|                 }
 | |
|                 local ColorPoint = Sq_New_Point(104);
 | |
|                 Sq_WriteBlobToAddress(ColorPoint, ColorBlob);
 | |
|                 ColorArr.append(ColorPoint);
 | |
| 
 | |
|             } else {
 | |
|                 SendStrBlob.writeblob(StrPointB);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         local SendStrLen = SendStrBlob.len();
 | |
|         local SendStrPoint = Sq_New_Point(SendStrLen);
 | |
|         Sq_WriteBlobToAddress(SendStrPoint, SendStrBlob);
 | |
| 
 | |
|         local Pack = Packet();
 | |
|         Pack.Put_Header(0, 370);
 | |
|         Pack.Put_Byte(Type);
 | |
|         Pack.Put_Short(0);
 | |
|         Pack.Put_Byte(3);
 | |
|         Pack.Put_Int(SendStrLen);
 | |
|         Pack.Put_BinaryEx(SendStrPoint, SendStrLen);
 | |
|         Pack.Put_Byte(ColorArr.len());
 | |
|         foreach(color in ColorArr) {
 | |
|             Pack.Put_BinaryEx(color, 104);
 | |
|         }
 | |
|         Pack.Finalize(true);
 | |
|         World.SendAll(Pack)
 | |
|         Pack.Delete();
 | |
|         // SendItemSpace(0);
 | |
| 
 | |
|         Sq_Delete_Point(SendStrPoint);
 | |
|         for (local i = 0; i< ColorArr.len(); i++) {
 | |
|             Sq_Delete_Point(ColorArr[i]);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     //发送公告消息  字符串数组 带ID
 | |
|     function SendNotiForColorAIdPacketMessage(StringArr, Type) {
 | |
| 
 | |
|         local ColorArr = [];
 | |
|         local SendStrBlob = blob(1);
 | |
|         SendStrBlob.writen(0xc2, 'c');
 | |
|         SendStrBlob.writen(0x80, 'c');
 | |
|         foreach(sobj in StringArr) {
 | |
|             local StrPoint = Str_Ptr(sobj[0]);
 | |
|             local StrPointB = Sq_Point2Blob(StrPoint, sobj[0].len());
 | |
|             if (sobj[1]) {
 | |
|                 SendStrBlob.writen(0xc2, 'c');
 | |
|                 SendStrBlob.writen(0x80, 'c');
 | |
|                 SendStrBlob.writeblob(StrPointB);
 | |
|                 SendStrBlob.writen(0xc2, 'c');
 | |
|                 SendStrBlob.writen(0x80, 'c');
 | |
| 
 | |
|                 local ColorBlob = blob(104);
 | |
|                 for (local i = 0; i< 3; i++) {
 | |
|                     ColorBlob.writen(sobj[2][i], 'c');
 | |
|                 }
 | |
|                 if (sobj[3]) {
 | |
|                     ColorBlob.seek(4);
 | |
|                     ColorBlob.writen(sobj[3], 'i');
 | |
|                 } else {
 | |
|                     for (local i = 0; i< 101; i++) {
 | |
|                         ColorBlob.writen(0xff, 'c');
 | |
|                     }
 | |
|                 }
 | |
|                 local ColorPoint = Sq_New_Point(104);
 | |
|                 Sq_WriteBlobToAddress(ColorPoint, ColorBlob);
 | |
|                 ColorArr.append(ColorPoint);
 | |
| 
 | |
|             } else {
 | |
|                 SendStrBlob.writeblob(StrPointB);
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         local SendStrLen = SendStrBlob.len();
 | |
|         local SendStrPoint = Sq_New_Point(SendStrLen);
 | |
|         Sq_WriteBlobToAddress(SendStrPoint, SendStrBlob);
 | |
| 
 | |
|         local Pack = Packet();
 | |
|         Pack.Put_Header(0, 370);
 | |
|         Pack.Put_Byte(Type);
 | |
|         Pack.Put_Short(0);
 | |
|         Pack.Put_Byte(3);
 | |
|         Pack.Put_Int(SendStrLen);
 | |
|         Pack.Put_BinaryEx(SendStrPoint, SendStrLen);
 | |
|         Pack.Put_Byte(ColorArr.len());
 | |
|         foreach(color in ColorArr) {
 | |
|             Pack.Put_BinaryEx(color, 104);
 | |
|         }
 | |
|         Pack.Finalize(true);
 | |
|         World.SendAll(Pack)
 | |
|         Pack.Delete();
 | |
|         // SendItemSpace(0);
 | |
| 
 | |
|         Sq_Delete_Point(SendStrPoint);
 | |
|         for (local i = 0; i< ColorArr.len(); i++) {
 | |
|             Sq_Delete_Point(ColorArr[i]);
 | |
|         }
 | |
|     }
 | |
| 
 | |
| 
 | |
|     //通过UID和CID获取玩家
 | |
|     function GetUserByUidCid(Uid, Cid) {
 | |
|         local SUser = GetUserByUid(Uid);
 | |
|         if (SUser) {
 | |
|             if (SUser.GetState() >= 3) {
 | |
|                 if (SUser.GetCID() == Cid) {
 | |
|                     return SUser;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|         return null;
 | |
|     }
 | |
|     //指定角色移动区域
 | |
|     function MoveArea(SUser, TownIndex, AreaIndex, Xpos, Ypos) {
 | |
|         Sq_GameWorld_MoveArea(Sq_Get_GameWorld(), SUser.C_Object, TownIndex, AreaIndex, Xpos, Ypos);
 | |
|     }
 | |
|     //副本进出
 | |
|     function SendDungeonInOut(SUser, Index, Model) {
 | |
|         Sq_GameWorld_SendDungeonInOut(Sq_Get_GameWorld(), SUser.C_Object, Index, Model);
 | |
|     }
 | |
|     //给所有玩家发送队伍包
 | |
|     function SendPartyInfoToAll(Party) {
 | |
|         Sq_GameWorld_SendPartyInfoToAll(Sq_Get_GameWorld(), Party.C_Object);
 | |
|     }
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
| 
 | |
|     //获取在线玩家列表表头
 | |
|     function api_gameworld_user_map_begin() {
 | |
|         local Begin = Sq_New_Point(4);
 | |
|         Sq_CallFunc(S_Ptr("0x80F78A6"), "int", ["pointer", "pointer"], Begin, Ptr_Operation_A2S(Sq_Get_GameWorld(), 308));
 | |
|         return Begin;
 | |
|     }
 | |
| 
 | |
|     //获取在线玩家列表表尾
 | |
|     function api_gameworld_user_map_end() {
 | |
|         local End = Sq_New_Point(4);
 | |
|         Sq_CallFunc(S_Ptr("0x80F78CC"), "int", ["pointer", "pointer"], End, Ptr_Operation_A2S(Sq_Get_GameWorld(), 308));
 | |
|         return End;
 | |
|     }
 | |
| 
 | |
|     //获取当前正在遍历的玩家
 | |
|     function api_gameworld_user_map_get(it) {
 | |
|         local Buf = Sq_CallFunc(S_Ptr("0x80F7944"), "pointer", ["pointer"], it);
 | |
|         local Buf2 = Ptr_Operation_A2S(Buf, 4);
 | |
|         local Buf3 = Sq_ReadPoint(Buf2);
 | |
|         return Buf3;
 | |
|     }
 | |
| 
 | |
|     //迭代器指针自增
 | |
|     function api_gameworld_user_map_next(it) {
 | |
|         local Next = Sq_New_Point(4);
 | |
|         Sq_CallFunc(S_Ptr("0x80F7906"), "pointer", ["pointer", "pointer"], Next, it);
 | |
|         Sq_Delete_Point(Next);
 | |
|         return Next;
 | |
|     }
 | |
|     //获取在线玩家列表
 | |
|     function GetOnlinePlayer() {
 | |
|         local PlayerArr = [];
 | |
|         //遍历在线玩家列表
 | |
|         local it = api_gameworld_user_map_begin();
 | |
|         local end = api_gameworld_user_map_end();
 | |
| 
 | |
|         //判断在线玩家列表遍历是否已结束
 | |
|         while (Sq_CallFunc(S_Ptr("0x80F78F2"), "bool", ["pointer", "pointer"], it, end)) {
 | |
|             //当前被遍历到的玩家
 | |
|             local user = api_gameworld_user_map_get(it);
 | |
|             local SUser = User(user);
 | |
|             if (SUser) PlayerArr.append(SUser);
 | |
|             //继续遍历下一个玩家
 | |
|             api_gameworld_user_map_next(it);
 | |
|         }
 | |
| 
 | |
|         Sq_Delete_Point(it);
 | |
|         Sq_Delete_Point(end);
 | |
|         return PlayerArr;
 | |
|     }
 | |
| } |