|
@@ -17,9 +17,9 @@ public class Robot
|
|
|
{
|
|
|
#region Config
|
|
|
|
|
|
- private static Vector2 LeftDownBorder; //todo
|
|
|
- private static Vector2 RightTop; //todo
|
|
|
- private static Camera Camera; //todo
|
|
|
+ private static Vector2 LeftDownBorder;
|
|
|
+ private static Vector2 RightTop;
|
|
|
+ private static Camera Camera;
|
|
|
|
|
|
private static bool Initialized;
|
|
|
private static int MinChestValue;
|
|
@@ -31,13 +31,12 @@ public class Robot
|
|
|
private static float DigitChestRate;
|
|
|
private static float MinMoveTime;
|
|
|
private static float MaxMoveTime;
|
|
|
- private static float MinRobotCreateTime;
|
|
|
- private static float MaxRobotCreateTime;
|
|
|
- private static string MaxRobotAmtFml;
|
|
|
+ public static string MaxRobotAmtFml;
|
|
|
private static string ConfigName = "robot_config";
|
|
|
private static string RootNodeName = "data";
|
|
|
private static string DataNodeName = "item";
|
|
|
|
|
|
+ private long RobotConfigID;
|
|
|
private string Nickname;
|
|
|
private Vector3 Position;
|
|
|
private PlayerDirection Direction;
|
|
@@ -66,13 +65,10 @@ public class Robot
|
|
|
XmlAttributeCollection attributes = dataNode.Attributes;
|
|
|
|
|
|
int index = 1;
|
|
|
- List<int> ints = Auxiliary.IntListParse(',', attributes[index++].Value, null);
|
|
|
- MinRobotCreateTime = ints[0];
|
|
|
- MaxRobotCreateTime = ints[1];
|
|
|
MaxRobotAmtFml = attributes[index++].Value;
|
|
|
DigitChestRate = float.Parse(attributes[index++].Value);
|
|
|
ColorChestRate = float.Parse(attributes[index++].Value);
|
|
|
- ints = Auxiliary.IntListParse(',', attributes[index++].Value, null);
|
|
|
+ List<int> ints = Auxiliary.IntListParse(',', attributes[index++].Value, null);
|
|
|
MinMoveTime = ints[0];
|
|
|
MaxMoveTime = ints[1];
|
|
|
CreateChestRate = float.Parse(attributes[index++].Value);
|
|
@@ -98,19 +94,47 @@ public class Robot
|
|
|
}
|
|
|
|
|
|
|
|
|
- public Robot(Vector3 position, PlayerDirection direction)
|
|
|
+ public Robot(long robotConfigID, bool randomPos, string nickname, List<string> dressdatas)
|
|
|
{
|
|
|
- Position = position;
|
|
|
- Direction = direction;
|
|
|
+ //if (randomPos)
|
|
|
+ //{
|
|
|
+ // Vector3? pos;
|
|
|
+ // while ((pos = Raycast()) == null);
|
|
|
+ // Position = pos.Value;
|
|
|
+ // Direction = (PlayerDirection) Random.Range(0, 2);
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // Position = SFSPlazaRoomManager.GetDefaultPosition();
|
|
|
+ // Direction = SFSPlazaRoomManager.DefaultDirection;
|
|
|
+ //}
|
|
|
+ Position = SFSPlazaRoomManager.GetDefaultPosition();
|
|
|
+ Direction = SFSPlazaRoomManager.DefaultDirection;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ RobotConfigID = robotConfigID;
|
|
|
+ Nickname = nickname;
|
|
|
+ DressdataNames = dressdatas;
|
|
|
+ DressdataIDs = ManaData.GetDressDataIDs(DressdataNames);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ foreach (var DressdataName in DressdataNames)
|
|
|
+ {
|
|
|
+ Debug.LogWarning(DressdataName);
|
|
|
+ }
|
|
|
+ Debug.LogWarning(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public void Connect(int sfsRoomID, int maxRobot)
|
|
|
+ public void Connect(int sfsRoomID)
|
|
|
{
|
|
|
- Debug.LogWarning("Robot connect");
|
|
|
+ //Debug.LogWarning("Robot connect");
|
|
|
SmartFox = new SmartFox();
|
|
|
SmartFox.AddEventListener(SFSEvent.CONNECTION, OnConnectReturn);
|
|
|
SmartFox.AddEventListener(SFSEvent.CONNECTION_LOST, (evt) => Deactivate(false));
|
|
|
- SmartFox.AddEventListener(SFSEvent.LOGIN, evt => { Mark(evt, sfsRoomID, maxRobot); });
|
|
|
+ SmartFox.AddEventListener(SFSEvent.LOGIN, evt => { Mark(evt, sfsRoomID); });
|
|
|
SmartFox.AddEventListener(SFSEvent.LOGIN_ERROR, (evt) => Deactivate(false));
|
|
|
SmartFox.AddEventListener(SFSEvent.LOGOUT, (evt) => Deactivate(false));
|
|
|
SmartFox.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
|
|
@@ -126,19 +150,19 @@ public class Robot
|
|
|
|
|
|
private void Login()
|
|
|
{
|
|
|
- Debug.LogWarning("Robot login");
|
|
|
+ //Debug.LogWarning("Robot login");
|
|
|
string userName = Random.Range(0f, 1000f).ToString();
|
|
|
SmartFox.Send(new LoginRequest(userName, ""));
|
|
|
}
|
|
|
|
|
|
- private void Mark(BaseEvent evt, int sfsRoomID, int maxRobot)
|
|
|
+ private void Mark(BaseEvent evt, int sfsRoomID)
|
|
|
{
|
|
|
- Debug.LogWarning("Robot mark");
|
|
|
+ //Debug.LogWarning("Robot mark");
|
|
|
User = (User) evt.Params["user"];
|
|
|
SFSObject arg = new SFSObject();
|
|
|
arg.PutInt(Label.CommandID, PlazaRoomReq.MarkAsRobot.GetHashCode());
|
|
|
arg.PutInt(Label.RoomID, sfsRoomID);
|
|
|
- arg.PutInt(Label.Data, maxRobot);
|
|
|
+ arg.PutLong(Label.UserID, RobotConfigID);
|
|
|
SendRequest(arg);
|
|
|
}
|
|
|
|
|
@@ -148,6 +172,12 @@ public class Robot
|
|
|
SmartFox.Send(new ExtensionRequest(HandlerID.PlazaRoom.GetHashString(), arg));
|
|
|
}
|
|
|
|
|
|
+ private void SendChestAwardRequest(long chestID)
|
|
|
+ {
|
|
|
+ SFSObject arg = PlazaRoomEvent.WrapChestAwardArg(chestID);
|
|
|
+ SendRequest(arg);
|
|
|
+ }
|
|
|
+
|
|
|
private void SendInstantiateRequest(int receiver)
|
|
|
{
|
|
|
SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendInstantiateRequset(User.Id, DressdataIDs.ToArray(), Position, Direction, Nickname, receiver);
|
|
@@ -158,12 +188,12 @@ public class Robot
|
|
|
{
|
|
|
if ((bool) evt.Params["success"])
|
|
|
{
|
|
|
- Debug.LogWarning("Robot connect succeed");
|
|
|
+ //Debug.LogWarning("Robot connect succeed");
|
|
|
Login();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Debug.LogWarning("Robot connect failed");
|
|
|
+ //Debug.LogWarning("Robot connect failed");
|
|
|
Deactivate(false);
|
|
|
}
|
|
|
}
|
|
@@ -180,7 +210,7 @@ public class Robot
|
|
|
{
|
|
|
Deactivate(false);
|
|
|
}
|
|
|
- else if (cmd == PlazaRoomRep.OtherEnterRoom.GetHashString()) //todo
|
|
|
+ else if (cmd == PlazaRoomRep.OtherEnterRoom.GetHashString())
|
|
|
{
|
|
|
OnOtherEnterRoom(evt);
|
|
|
}
|
|
@@ -211,34 +241,12 @@ public class Robot
|
|
|
private bool Activated;
|
|
|
private void Activate(BaseEvent evt)
|
|
|
{
|
|
|
- if (!SFSManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
|
|
|
- {
|
|
|
- Deactivate(false);
|
|
|
- }
|
|
|
-
|
|
|
- Debug.LogWarning("Robot Activate");
|
|
|
+ //Debug.LogWarning("Robot Activate");
|
|
|
Activated = true;
|
|
|
MoveTime = Random.Range(MinMoveTime, MaxMoveTime);
|
|
|
LifetimeTime = Random.Range(MinLifetime, MaxLifetime);
|
|
|
CreateChestTime = Random.Range(0, LifetimeTime);
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- ISFSObject arg = evt.Params["params"] as ISFSObject;
|
|
|
- Nickname = arg.GetUtfString(Label.Data);
|
|
|
- DressdataNames = arg.GetUtfStringArray(Label.DataArray).ToList();
|
|
|
- DressdataIDs = ManaData.GetDressDataIDs(DressdataNames);
|
|
|
- SendInstantiateRequest(-1);
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- foreach (var DressdataName in DressdataNames)
|
|
|
- {
|
|
|
- Debug.LogWarning(DressdataName);
|
|
|
- }
|
|
|
- Debug.LogWarning(e);
|
|
|
- Deactivate(false);
|
|
|
- }
|
|
|
+ SendInstantiateRequest(-1);
|
|
|
}
|
|
|
|
|
|
private bool Behaviour()
|
|
@@ -248,14 +256,19 @@ public class Robot
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- //if (LifetimeBehaviour())
|
|
|
- //{
|
|
|
- // return true;
|
|
|
- //}
|
|
|
+ if (!SFSManager.GardenSmartFox.PlazaRoomManager.InPlazaRoom)
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (LifetimeBehaviour())
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
- //MoveBehaviour();
|
|
|
- //CreateChestBehaviour();
|
|
|
- //GetChestAwardBehaviour();
|
|
|
+ MoveBehaviour();
|
|
|
+ CreateChestBehaviour();
|
|
|
+ GetChestAwardBehaviour();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -267,25 +280,38 @@ public class Robot
|
|
|
if (MoveTimer >= MoveTime)
|
|
|
{
|
|
|
MoveTimer = 0;
|
|
|
- Debug.LogWarning("Robot move");
|
|
|
- Raycast();
|
|
|
+ //Debug.LogWarning("Robot move");
|
|
|
+ Vector3? pos = Raycast();
|
|
|
+ if (pos != null)
|
|
|
+ {
|
|
|
+ Position = pos.Value;
|
|
|
+ SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendSynchronizeDestination(User.Id, Position);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void Raycast() //todo
|
|
|
+ private Vector3? Raycast()
|
|
|
{
|
|
|
Vector3 origin = new Vector3(Random.Range(LeftDownBorder.x, RightTop.x), Random.Range(LeftDownBorder.y, RightTop.y), Camera.transform.position.z);
|
|
|
Ray ray = new Ray(origin, Vector3.forward);
|
|
|
RaycastHit hitInfo;
|
|
|
if (Physics.Raycast(ray, out hitInfo))
|
|
|
{
|
|
|
- Vector3 destination = PlazaRoom.HitPositionToDestination(hitInfo.point);
|
|
|
- SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.SendSynchronizeDestination(User.Id, destination);
|
|
|
- Position = destination;
|
|
|
+ if (hitInfo.collider.tag == Tags.PlazaChestTag)
|
|
|
+ {
|
|
|
+ //Debug.LogWarning("射线被箱子阻挡");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Vector3 destination = PlazaRoom.HitPositionToDestination(hitInfo.point);
|
|
|
+ return destination;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Debug.LogWarning("射线检测失败");
|
|
|
+ //Debug.LogWarning("射线检测失败");
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -297,7 +323,7 @@ public class Robot
|
|
|
LifetimeTimer += Time.deltaTime;
|
|
|
if (LifetimeTimer >= LifetimeTime)
|
|
|
{
|
|
|
- Debug.LogWarning("Robot lifetime over");
|
|
|
+ //Debug.LogWarning("Robot lifetime over");
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
@@ -309,7 +335,7 @@ public class Robot
|
|
|
private bool CreateChestLock;
|
|
|
private float CreateChestTime;
|
|
|
private float CreateChestTimer;
|
|
|
- private void CreateChestBehaviour() //todo
|
|
|
+ private void CreateChestBehaviour()
|
|
|
{
|
|
|
if (CreateChestLock)
|
|
|
{
|
|
@@ -322,39 +348,39 @@ public class Robot
|
|
|
CreateChestLock = true;
|
|
|
if (Random.Range(0f, 1f) >= CreateChestRate)
|
|
|
{
|
|
|
- Debug.LogWarning("create chest ran out of luck");
|
|
|
+ //Debug.LogWarning("create chest ran out of luck");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- Debug.LogWarning("Robot create a chest");
|
|
|
+ //Debug.LogWarning("Robot create a chest");
|
|
|
RoomData roomData = SFSManager.GardenSmartFox.PlazaRoomManager.CurrentRoomData;
|
|
|
int round = Random.Range(1, roomData.MaxPlayer + 1);
|
|
|
int value = Random.Range(MinChestValue, MaxChestValue);
|
|
|
- Vector3 position = ChestMge.PlayerPosToChestPos(Position);
|
|
|
+ Vector3 playerPos = SFSManager.GardenSmartFox.PlazaRoomManager.UserInstanceDictionary[User.Id].Player.transform.position;
|
|
|
+ Vector3 chestPos = ChestMge.PlayerPosToChestPos(playerPos);
|
|
|
ChestType type = (ChestType) Random.Range(1, 4);
|
|
|
- SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.CreateChest(round, value, type, roomData.ID, -1, position);
|
|
|
+ SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.CreateChest(round, value, type, roomData.ID, -2, chestPos);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private float GetChestTime = 3;
|
|
|
private float GetChestTimer;
|
|
|
- private float MaxChestDistance = 8; //todo
|
|
|
+ private float MaxChestDistance = 8;
|
|
|
private List<long> OperatedChestIDs = new List<long>();
|
|
|
- private void GetChestAwardBehaviour() //todo
|
|
|
+ private void GetChestAwardBehaviour()
|
|
|
{
|
|
|
GetChestTimer += Time.deltaTime;
|
|
|
if (GetChestTimer >= GetChestTime)
|
|
|
{
|
|
|
GetChestTimer = 0;
|
|
|
- Debug.LogWarning("Robot try get some chests");
|
|
|
+ //Debug.LogWarning("Robot try get some chests");
|
|
|
List<PlazaRoomChest> chests = DetectChest();
|
|
|
- Debug.LogWarning($"{chests.Count} chest/chests is available");
|
|
|
+ //Debug.LogWarning($"{chests.Count} chest/chests is available");
|
|
|
for (int i = 0; i < chests.Count; i++)
|
|
|
{
|
|
|
TryGetChestAward(chests[i]);
|
|
|
}
|
|
|
}
|
|
|
- //Debug.LogWarning("robot get a chest");
|
|
|
}
|
|
|
|
|
|
private List<PlazaRoomChest> DetectChest()
|
|
@@ -367,7 +393,7 @@ public class Robot
|
|
|
{
|
|
|
if (OperatedChestIDs.Contains(ChestMge.PlazaRoomChests[i].ChestData.ID))
|
|
|
{
|
|
|
- Debug.LogWarning("this chest has been operated");
|
|
|
+ //Debug.LogWarning("this chest has been operated");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -376,7 +402,8 @@ public class Robot
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Debug.LogWarning("this chest is too far");
|
|
|
+ //Debug.LogWarning("this chest is too far");
|
|
|
+ //Debug.LogWarning(Mathf.Abs(ChestMge.PlazaRoomChests[i].transform.position.x - Position.x));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -409,6 +436,17 @@ public class Robot
|
|
|
get = false;
|
|
|
}
|
|
|
}
|
|
|
+ else if (chest.ChestData.ChestType == ChestType.System)
|
|
|
+ {
|
|
|
+ if (chest.IsActive)
|
|
|
+ {
|
|
|
+ get = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ get = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
get = true;
|
|
@@ -417,11 +455,12 @@ public class Robot
|
|
|
OperatedChestIDs.Add(chest.ChestData.ID);
|
|
|
if (get)
|
|
|
{
|
|
|
- SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.GetChestAward(chest.ChestData.ID);
|
|
|
+ SendChestAwardRequest(chest.ChestData.ID);
|
|
|
+ //Debug.LogWarning("get a chest");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Debug.LogWarning("get chest ran out of luck");
|
|
|
+ //Debug.LogWarning("get chest ran out of luck");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -430,7 +469,7 @@ public class Robot
|
|
|
private static float MaxDelayTime = 10f;
|
|
|
public void Deactivate(bool delay)
|
|
|
{
|
|
|
- Debug.LogWarning("Robot disconnect");
|
|
|
+ //Debug.LogWarning("Robot disconnect " + delay);
|
|
|
Activated = false;
|
|
|
|
|
|
if (delay)
|