소스 검색

增加机器人功能

LiuQilin 7 년 전
부모
커밋
8f3556a538

+ 1 - 0
Assets/Resource/Prefab/Object/DebugMode.prefab

@@ -287,5 +287,6 @@ MonoBehaviour:
   - {fileID: 4900000, guid: 37311be8685a98c4a850ea2c4ecd7bb4, type: 3}
   - {fileID: 4900000, guid: 8d5d74d2d26a2be46a1f875c6130a57f, type: 3}
   - {fileID: 4900000, guid: b9413a82e8f919e46b0c37372b491307, type: 3}
+  - {fileID: 4900000, guid: ca67a0705396bba4b90fb3fc76541bf7, type: 3}
   DiscardList: []
   PlazaRoomList: []

+ 1 - 1
Assets/Resource/Prefab/PrefabUI/GroupA.prefab

@@ -7055,7 +7055,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   m_Material: {fileID: 0}
-  m_Color: {r: 1, g: 0.654902, b: 0.15294118, a: 1}
+  m_Color: {r: 0.64705884, g: 0.7529412, b: 0.78431374, a: 1}
   m_RaycastTarget: 1
   m_OnCullStateChanged:
     m_PersistentCalls:

+ 1 - 1
Assets/Resource/XML/Config/plaza_room_config.xml

@@ -1,5 +1,5 @@
 <data>
-  <item id="1" create_cost_fml="h*50+p*5" cost_value_fml="c*0.8" />
+  <item id="1" create_cost_fml="h*50+p*10" cost_value_fml="c*0.8" />
   <comment>
     <id>
 id

+ 3 - 2
Assets/Resource/XML/PlayerConfig.xml

@@ -1,6 +1,7 @@
 <PlayerConfig>
-  <Version value="10" />
-
+  <Version value="11" />
+  <ReplayVersion value="0" />
+  
   <ID value="Default" />
   <SerialNumber value="Default" />
   

BIN
Assets/Resource/Xlsx/plaza_room_config.xlsx


BIN
Assets/Resource/Xlsx/robot_config.xlsx


+ 1 - 0
Assets/Script/Manage/ManaCenter.cs

@@ -714,6 +714,7 @@ public class ManaCenter : Regist
 
     public override void RegistValueA()
     {
+        //Debug.LogWarning(ManaData.GetPlayerInt("ReplayVersion"));
         ManaReso.Get<Graphic>("F_Elf").material = ManaReso.Load<Material>("GrayMat", Folder.UI);
         ManaReso.Get<Graphic>("F_Store").material = ManaReso.Load<Material>("GrayMat", Folder.UI);
         ManaReso.Get<Graphic>("F_Magic").material = ManaReso.Load<Material>("GrayMat", Folder.UI);

+ 29 - 3
Assets/Script/Manage/ManaData.cs

@@ -90,8 +90,15 @@ public class ManaData : Regist
                     else
                     {
                         nativeVersion = int.Parse(node.Attributes[0].Value);
-                        
-                        if (nativeVersion < defaultVersion)
+
+                        if (nativeVersion == -1000)
+                        {
+                            PlayerDoc_ = DefaultDoc;
+                            int currentReplayVersion = int.Parse(nativeDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("ReplayVersion").Attributes[0].Value);
+                            SavePlayerInt("ReplayVersion", currentReplayVersion+1);
+                            //Debug.Log(currentReplayVersion);
+                        }
+                        else if (nativeVersion < defaultVersion)
                         {
                             byte[] bytes;
 
@@ -588,7 +595,7 @@ public class ManaData : Regist
 
     public static void ResetPlayerConfig()
     {
-        PlayerNode.SelectSingleNode("Version").Attributes[0].Value = "10000";
+        PlayerNode.SelectSingleNode("Version").Attributes[0].Value = "-1000";
 
         SavePlayerConfig();
 
@@ -1142,6 +1149,9 @@ public class ManaData : Regist
     }
 
 
+    //玩家存档版本大于默认存档版本时需要清空
+    //玩家存档版本小于默认存档版本时需要合并
+    //玩家存档版本等于-1000时需要标记为重玩
     public static XmlDocument MergeXML(int nativeVersion, XmlDocument nativeDoc, XmlDocument defaultDoc)
     {
         if (nativeVersion < 0)
@@ -1221,6 +1231,13 @@ public class ManaData : Regist
             To10(nativeDoc, defaultDoc);
         }
 
+        if (nativeVersion < 11)
+        {
+            Debug.LogWarning("UpdateArchive to 11");
+
+            To11(nativeDoc, defaultDoc);
+        }
+
         return nativeDoc;
     }
 
@@ -1435,4 +1452,13 @@ public class ManaData : Regist
         ChestMge.ClearRefundAndOperateData(nativeDoc.SelectSingleNode("PlayerConfig"));
         return nativeDoc;
     }
+
+    public static XmlDocument To11(XmlDocument nativeDoc, XmlDocument defaultDoc)
+    {
+        XmlNode xmlNode = defaultDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("ReplayVersion");
+
+        nativeDoc.SelectSingleNode("PlayerConfig").AppendChild(nativeDoc.ImportNode(xmlNode, true));
+
+        return nativeDoc;
+    }
 }

+ 4 - 4
Assets/Script/Manage/ManaSign.cs

@@ -691,10 +691,10 @@ public class ManaSign : Regist
             return true;
         }
 
-        if (ShowNotification())
-        {
-            return true;
-        }
+        //if (ShowNotification())
+        //{
+        //    return true;
+        //}
 
         if (ManaNickName.ShowNickNameSettingPanelFirstTime())
         {

+ 4 - 3
Assets/Script/SFS/Manager/BaseConnector.cs

@@ -8,9 +8,10 @@ public abstract class BaseConnector
 {
     public GardenSmartFox GardenSmartFox;
 
-    public int TcpPort = 9933;
-    public string Host = "121.199.20.79";
-    //public string Host = "127.0.0.1";
+    public static int TcpPort = 9933;
+    //public static string Host = "121.199.20.79";
+    public static string Host = "127.0.0.1";
+    public static string Zone = "Garden";
 
     public Action<BaseEvent> onConnectSucceed;
     public Action<BaseEvent> onConnectFailed;

+ 0 - 3
Assets/Script/SFS/Manager/BaseLoggor.cs

@@ -8,9 +8,6 @@ public abstract class BaseLoggor
 {
     public GardenSmartFox GardenSmartFox;
 
-    public string UserName = "";
-    public string Password = "";
-
     public Action<BaseEvent> onLogin;
     public Action<BaseEvent> onLoginError;
     public Action<BaseEvent> onLogout;

+ 0 - 2
Assets/Script/SFS/Manager/Connector.cs

@@ -8,8 +8,6 @@ using Sfs2X.Requests;
 [Serializable]
 public class Connector : BaseConnector
 {
-    public string Zone = "Garden";
-
     public Connector()
     {
         onConnectSucceed += baseEvent =>

+ 2 - 2
Assets/Script/SFS/Manager/Loggor.cs

@@ -21,9 +21,9 @@ public class Loggor : BaseLoggor
     {
         //Debug.Log("Send login request");
 
-        UserName = Random.Range(0f, 100f).ToString();
+        string userName = Random.Range(0f, 1000f).ToString();
 
-        GardenSmartFox.SmartFox.Send(new LoginRequest(UserName, Password));
+        GardenSmartFox.SmartFox.Send(new LoginRequest(userName, ""));
     }
 
     public override void Logout()

+ 39 - 9
Assets/Script/SFS/Manager/RobotManager.cs

@@ -1,23 +1,53 @@
-using System.Collections;
+using System;
+using System.Collections;
 using System.Collections.Generic;
+using Random = UnityEngine.Random;
 
-using UnityEngine;
-
-public class RobotManager : MonoBehaviour
+public class RobotManager
 {
     #region Config
-    
-    
+
+    public static List<Robot> Robots = new List<Robot>();
 
     #endregion
 
-    public void Start()
+    public static void AddRobot(int sfsRoomID, int maxRobot)
     {
-
+        Robot.Initialize();
+        Robot robot = new Robot();
+        robot.Connect(sfsRoomID, maxRobot);
+        Robots.Add(robot);
     }
 
-    public void Update()
+    private static float MinRandomTime = 3f;
+    private static float MaxRandomTime = 10f;
+    public static void DeactivateAllRobots(bool afterRandomTime)
     {
+        if (afterRandomTime)
+        {
+            foreach (var robot in Robots)
+            {
+                DelayCall.Call(Random.Range(MinRandomTime, MaxRandomTime), robot.Deactivate);
+            }
+        }
+        else
+        {
+            foreach (var robot in Robots)
+            {
+                robot.Deactivate();
+            }
+        }
+        Robots = new List<Robot>();
+    }
 
+    public static void Update()
+    {
+        for (int i = 0; i < Robots.Count; i++)
+        {
+            if (Robots[i].Update())
+            {
+                Robots[i--].Deactivate();
+            }
+        }
     }
 }

+ 2 - 0
Assets/Script/SFS/Manager/SFSManager.cs

@@ -112,6 +112,8 @@ public class SFSManager : Regist
     {
         if (GardenSmartFox != null)
             GardenSmartFox.Connector.Disconnect();
+
+        RobotManager.DeactivateAllRobots(false);
     }
 
 

+ 13 - 25
Assets/Script/SFS/Manager/SFSPlazaRoomManager.cs

@@ -167,7 +167,6 @@ public class SFSPlazaRoomManager
     public bool InPlazaRoom;
 
     public bool IsBlackMaskFinish;
-    public bool EnteringPlazaRoom;
     public JoinRoomResult JoinRoomResult = JoinRoomResult.Pending;
 
     public Dictionary<int, PlazaRoomPlayer> UserInstanceDictionary = new Dictionary<int, PlazaRoomPlayer>();
@@ -235,8 +234,6 @@ public class SFSPlazaRoomManager
         if (JoinRoomResult == JoinRoomResult.Succeed)
         {
             EnterPlazaRoom();
-
-            EnteringPlazaRoom = false;
         }
         else
         {
@@ -254,8 +251,6 @@ public class SFSPlazaRoomManager
             {
                 Bubble.Show(null, Language.GetStr("UI", "Z_Unknown"), null, null, () => { ManaReso.Get("V_BlackMask").TweenForCG(); }, null, false);
             }
-
-            EnteringPlazaRoom = false;
         }
     }
 
@@ -337,6 +332,7 @@ public class SFSPlazaRoomManager
                 ManaReso.Get("B_SignIn0").TweenForCG();
                 ManaReso.Get("T_NickName").TweenForCG();
 
+                ManaReso.Get<Text>("X_CurrentInfoLab").text = "";
                 Transform tra = ManaReso.Get("X_Info");
                 while (tra.childCount > 0)
                 {
@@ -349,6 +345,8 @@ public class SFSPlazaRoomManager
                 }
 
                 UserInstanceDictionary = new Dictionary<int, PlazaRoomPlayer>();
+
+                RobotManager.DeactivateAllRobots(true);
             }
         );
 
@@ -386,12 +384,12 @@ public class SFSPlazaRoomManager
         if (!JoinedPlazaRoom)
             return;
 
-        if (EnteringPlazaRoom)
+        if (!InPlazaRoom)
             return;
 
         //KeepAliveThread();
         //CheckDefautChestThread();
-
+        RobotThread();
         CameraControllThread();
     }
 
@@ -417,16 +415,6 @@ public class SFSPlazaRoomManager
     public Camera PlazaRoomCamera;
     public void CameraControllThread()
     {
-        if (PlazaRoomCamera == null)
-        {
-            return;
-        }
-
-        if (!InPlazaRoom)
-        {
-            return;
-        }
-
         float x;
 
         if (SelfInstance.Player.transform.position.x <= CameraLeftBorder)
@@ -451,6 +439,13 @@ public class SFSPlazaRoomManager
         PlazaRoomCamera.transform.SetX(x);
     }
 
+
+    public void RobotThread()
+    {
+        RobotManager.Update();
+    }
+
+
     private float CheckTime = 10;
     private float CheckTimer;
     public void CheckDefautChestThread()
@@ -648,14 +643,7 @@ public class SFSPlazaRoomManager
 
     public void SendInstantiateRequset(int receiverID)
     {
-        SFSObject parameter = new SFSObject();
-        parameter.PutInt(InfoLabel.SenderID.GetHashString(), GardenSmartFox.User.Id);
-        parameter.PutIntArray(InfoLabel.Close.GetHashString(), ManaData.GetDressDataIDs(SelfInstance.Player).ToArray());
-        parameter.PutUtfString(InfoLabel.Position.GetHashString(), SelfInstance.Player.transform.position.VectorToString());
-        parameter.PutInt(InfoLabel.PlayerDirection.GetHashString(), SelfInstance.Player.PlayerDirection.GetHashCode());
-        parameter.PutUtfString(InfoLabel.NickName.GetHashString(), ManaNickName.NickName);
-
-        GardenSmartFox.AddRequest(PlazaRoomEvent.WrapInfoRequest(CurrentPlazaRoom.Id, receiverID, InfoID.Instantiate, parameter), RequestType.Immediate);
+        SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendInstantiateRequset(GardenSmartFox.User.Id, ManaData.GetDressDataIDs(SelfInstance.Player).ToArray(), SelfInstance.Player.transform.position, SelfInstance.Player.PlayerDirection, ManaNickName.NickName, receiverID);
 
         if (SelfInstance.IsMoving)
         {

+ 184 - 18
Assets/Script/SFS/Object/Robot.cs

@@ -1,7 +1,12 @@
 using System.Collections;
 using System.Collections.Generic;
+using System.Security.Policy;
 using System.Xml;
 using Sfs2X;
+using Sfs2X.Core;
+using Sfs2X.Entities.Data;
+using Sfs2X.Requests;
+using Sfs2X.Util;
 using UnityEngine;
 
 public class Robot
@@ -25,10 +30,6 @@ public class Robot
     private static string RootNodeName = "data";
     private static string DataNodeName = "item";
 
-
-    private float LifetimeTimer;
-    private float MoveTimer;
-
     private SmartFox SmartFox;
     
     #endregion
@@ -63,28 +64,193 @@ public class Robot
         MinLifetime = ints[0];
         MaxLifetime = ints[1];
 
-        Debug.Log($"RobotConfig {MinRobotCreateTime}");
-        Debug.Log($"RobotConfig {MaxRobotCreateTime}");
-        Debug.Log($"RobotConfig {MaxRobotAmtFml}");
-        Debug.Log($"RobotConfig {DigitChestRate}");
-        Debug.Log($"RobotConfig {ColorChestRate}");
-        Debug.Log($"RobotConfig {MinMoveTime}");
-        Debug.Log($"RobotConfig {MaxMoveTime}");
-        Debug.Log($"RobotConfig {CreateChestRate}");
-        Debug.Log($"RobotConfig {MinChestValue}");
-        Debug.Log($"RobotConfig {MaxChestValue}");
-        Debug.Log($"RobotConfig {MinLifetime}");
-        Debug.Log($"RobotConfig {MaxLifetime}");
+        //Debug.Log($"RobotConfig {MinRobotCreateTime}");
+        //Debug.Log($"RobotConfig {MaxRobotCreateTime}");
+        //Debug.Log($"RobotConfig {MaxRobotAmtFml}");
+        //Debug.Log($"RobotConfig {DigitChestRate}");
+        //Debug.Log($"RobotConfig {ColorChestRate}");
+        //Debug.Log($"RobotConfig {MinMoveTime}");
+        //Debug.Log($"RobotConfig {MaxMoveTime}");
+        //Debug.Log($"RobotConfig {CreateChestRate}");
+        //Debug.Log($"RobotConfig {MinChestValue}");
+        //Debug.Log($"RobotConfig {MaxChestValue}");
+        //Debug.Log($"RobotConfig {MinLifetime}");
+        //Debug.Log($"RobotConfig {MaxLifetime}");
+    }
+
+    public void Connect(int sfsRoomID, int maxRobot)
+    {
+        Debug.LogWarning("Robot connect");
+        SmartFox = new SmartFox();
+        SmartFox.AddEventListener(SFSEvent.CONNECTION, OnConnectReturn);
+        SmartFox.AddEventListener(SFSEvent.CONNECTION_LOST, OnActivateError);
+        SmartFox.AddEventListener(SFSEvent.LOGIN, evt => { Mark(sfsRoomID, maxRobot); });
+        SmartFox.AddEventListener(SFSEvent.LOGIN_ERROR, OnActivateError);
+        SmartFox.AddEventListener(SFSEvent.LOGOUT,  OnActivateError);
+        SmartFox.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
+
+        ConfigData configData = new ConfigData
+        {
+            Host = BaseConnector.Host,
+            Port = BaseConnector.TcpPort,
+            Zone = BaseConnector.Zone,
+        };
+        SmartFox.Connect(configData);
     }
 
+    private void Login()
+    {
+        Debug.LogWarning("Robot login");
+        string userName = Random.Range(0f, 1000f).ToString();
+        SmartFox.Send(new LoginRequest(userName, ""));
+    }
 
-    public void Start()
+    private void Mark(int sfsRoomID, int maxRobot)
     {
+        Debug.LogWarning("Robot mark");
+        SFSObject arg = new SFSObject();
+        arg.PutInt(Label.CommandID, PlazaRoomReq.MarkAsRobot.GetHashCode());
+        arg.PutInt(Label.RoomID, sfsRoomID);
+        arg.PutInt(Label.Data, maxRobot);
+        SendRequest(arg);
+    }
 
+    private void SendRequest(SFSObject arg)
+    {
+        arg = GardenSmartFox.WrapIntoArray(new List<SFSObject> { arg });
+        SmartFox.Send(new ExtensionRequest(HandlerID.PlazaRoom.GetHashString(), arg));
     }
 
-    public void Update()
+
+    private void OnConnectReturn(BaseEvent evt)
     {
+        if ((bool)evt.Params["success"])
+        {
+            Debug.LogWarning("Robot connect succeed");
+            Login();
+        }
+        else
+        {
+            Debug.LogWarning("Robot connect failed");
+            OnActivateError(null);
+        }
+    }
 
+    private void OnExtensionResponse(BaseEvent evt)
+    {
+        string cmd = evt.Params["cmd"].ToString();
+
+        if (cmd == PlazaRoomRep.JoinRoomSucceed.GetHashString())
+        {
+            Activate();
+        }
+        else if (cmd == PlazaRoomRep.MarkRobotError.GetHashString())
+        {
+            OnActivateError(evt);
+        }
+    }
+
+
+    public bool Update()
+    {
+        if (SmartFox != null)
+        {
+            SmartFox.ProcessEvents();
+        }
+
+        return Behaviour();
+    }
+
+    private bool Activated;
+    private void Activate()
+    {
+        Debug.LogWarning("Robot Activate");
+        Activated = true;
+        MoveTime = Random.Range(MinMoveTime, MaxMoveTime);
+        LifetimeTime = Random.Range(MinLifetime, MaxLifetime);
+        CreateChestTime = Random.Range(0, LifetimeTime);
+    }
+
+    private bool Behaviour()
+    {
+        if (!Activated)
+        {
+            return false;
+        }
+
+        if (LifetimeBehaviour())
+        {
+            return true;
+        }
+
+        MoveBehaviour();
+        CreateChestBehaviour();
+        GetChestAwardBehaviour();
+        return false;
+    }
+
+    private float MoveTime;
+    private float MoveTimer;
+    private void MoveBehaviour()
+    {
+        MoveTimer += Time.deltaTime;
+        if (MoveTimer >= MoveTime)
+        {
+            MoveTimer = 0;
+            Debug.LogWarning("Robot move");
+        }
+    }
+
+    private float LifetimeTime;
+    private float LifetimeTimer;
+    private bool LifetimeBehaviour()
+    {
+        LifetimeTimer += Time.deltaTime;
+        if (LifetimeTimer >= LifetimeTime)
+        {
+            Debug.LogWarning("Robot lifetime over");
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    private bool CreateChestLock;
+    private float CreateChestTime;
+    private float CreateChestTimer;
+    private void CreateChestBehaviour()
+    {
+        if (CreateChestLock)
+        {
+            return;
+        }
+
+        CreateChestTimer += Time.deltaTime;
+        if (CreateChestTimer >= CreateChestTime)
+        {
+            Debug.LogWarning("Robot create chest");
+            CreateChestLock = true;
+        }
+    }
+
+    private void GetChestAwardBehaviour()
+    {
+        //Debug.LogWarning("robot get a chest");
+    }
+
+
+    public void Deactivate()
+    {
+        Debug.LogWarning("Robot disconnect");
+        SmartFox.Disconnect();
+        Activated = false;
+    }
+
+    private void OnActivateError(BaseEvent evt)
+    {
+        Debug.LogWarning("Robot activate error");
+        RobotManager.Robots.Remove(this);
     }
 }

+ 12 - 0
Assets/Script/SFS/SFSEvent/PlazaRoomEvent.cs

@@ -97,6 +97,18 @@ public class PlazaRoomEvent
     }
 
 
+    public void SendInstantiateRequset(int senderID, int[] dressDataIDs, Vector3 position, PlayerDirection direction, string nickname,  int receiverID)
+    {
+        SFSObject parameter = new SFSObject();
+        parameter.PutInt(InfoLabel.SenderID.GetHashString(), senderID);
+        parameter.PutIntArray(InfoLabel.Close.GetHashString(), dressDataIDs);
+        parameter.PutUtfString(InfoLabel.Position.GetHashString(), position.VectorToString());
+        parameter.PutInt(InfoLabel.PlayerDirection.GetHashString(), direction.GetHashCode());
+        parameter.PutUtfString(InfoLabel.NickName.GetHashString(), nickname);
+
+        SFSEventManager.GardenSmartFox.AddRequest(WrapInfoRequest(CurrentPlazaRoom.Id, receiverID, InfoID.Instantiate, parameter), RequestType.Immediate);
+    }
+
     public void SendSynchronizeDestination(Vector3 destination)
     {
         SFSObject sfsObject = new SFSObject();

+ 8 - 2
Assets/Script/Tool/Auxiliary.cs

@@ -142,7 +142,7 @@ public class Auxiliary : Regist
 
         if (Input.GetKeyDown(KeyCode.Space))
         {
-            Robot.Initialize();
+            RobotManager.AddRobot(1, 3);
             //Resources.UnloadAsset(ManaReso.Get("U_LoadingPanel"));
             //foreach (var VARIABLE in ChestMge.PlazaRoomChests)
             //{
@@ -159,7 +159,13 @@ public class Auxiliary : Regist
 
         if (Input.GetKeyDown(KeyCode.A))
         {
-            ManaSocial.UpdatePage(true);
+            URLRequestData urlData = new URLRequestData();
+
+            urlData.Add("i", "");
+
+            URLRequest.CreateURLRequest(false, ManaServer.NewBaseURL + "/user/rand", urlData, data => { Debug.Log(data.ToJson()); }, URLRequest.Method.POST);
+
+            //ManaSocial.UpdatePage(true);
             //PlazaRoomMge.DownloadRoomData(0);
             //DatabaseManager.GetRoomList(-1);
 

+ 4 - 9
第四期.txt

@@ -1,3 +1,6 @@
+收到MarkError后就不再创建机器人
+
+
 开启公告
 
 
@@ -13,12 +16,4 @@
 
 //更新版本号
 
-IOS设置Team
-
-
-内存优化(释放掉loading界面 教程中的选任务边框)
-
-Drawcall优化(聊天界面 表情 广场背景图片 宝箱 评论 点赞 公告 截图按钮 派对图标 上衣按钮需要打入图集)
-
-
-小任务-资源导入器(花园导入Dragonbones后自动进行后续处理)
+IOS设置Team