public bool PerformSAI(string action, Newtonsoft.Json.Linq.JArray input, Vector3 origin)
        {
            if (action != "place")
            {
                Debug.Log("Don't Recognize Action: " + action);
                return(false);
            }

            if (this.checkpoint)
            {
                Debug.Log("Can't act on a checkpount!");
                return(false);
            }

            if (this.name == "GoalTrigger")
            {
                Debug.Log("Can't act on the GoalTrigger");
                return(false);
            }

            float new_x   = float.NaN;
            float new_y   = float.NaN;
            float new_rot = float.NaN;

            new_x   = origin.x + input.Value <float>(0);
            new_y   = origin.y + input.Value <float>(1);
            new_rot = input.Value <float>(2);

            float curr_rot = this.transform.rotation.eulerAngles.z;

            if (Approx(curr_rot, new_rot))
            {
                BackUp();
                this.transform.position = new Vector3(new_x, new_y, 0);
                this.acting             = true;
                if (this.block)
                {
                    PerformBlockStuff();
                }
                return(true);
            }
            else
            {
                BackUp();
                Vector3 currEuler = this.transform.rotation.eulerAngles;
                currEuler.z             = new_rot;
                this.transform.rotation = Quaternion.Euler(currEuler);
                this.transform.position = new Vector3(new_x, new_y, 0);
                this.acting             = true;
                if (this.block)
                {
                    PerformBlockStuff();
                }
                return(true);
            }
        }
Пример #2
0
        public SceneMode GetMode()
        {
            // Send
            List <object> args = new List <object>()
            {
            };
            int           funcId = 9;
            List <object> obj    = new List <object>()
            {
                funcId, args
            };

            TCPHelper.Send(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
            // Receive
            string str = TCPHelper.Receive();

            Newtonsoft.Json.Linq.JArray o = (Newtonsoft.Json.Linq.JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(str);
            return(o.Value <SceneMode>(0));
        }
Пример #3
0
        public bool UseSpell(int spellId, SpellCastTargetInfoView target)
        {
            // Send
            List <object> args = new List <object>()
            {
                spellId, target
            };
            int           funcId = 8;
            List <object> obj    = new List <object>()
            {
                funcId, args
            };

            TCPHelper.Send(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
            // Receive
            string str = TCPHelper.Receive();

            Newtonsoft.Json.Linq.JArray o = (Newtonsoft.Json.Linq.JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(str);
            return(o.Value <bool>(0));
        }
Пример #4
0
        public bool StartMoveTo(Vector2 position)
        {
            // Send
            List <object> args = new List <object>()
            {
                position
            };
            int           funcId = 3;
            List <object> obj    = new List <object>()
            {
                funcId, args
            };

            TCPHelper.Send(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
            // Receive
            string str = TCPHelper.Receive();

            Newtonsoft.Json.Linq.JArray o = (Newtonsoft.Json.Linq.JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(str);
            return(o.Value <bool>(0));
        }
Пример #5
0
        public bool MoveShip(int index, Vector2 dir)
        {
            // Send
            List <object> args = new List <object>()
            {
                index, dir
            };
            int           funcId = 3;
            List <object> obj    = new List <object>()
            {
                funcId, args
            };

            TCPHelper.Send(Newtonsoft.Json.JsonConvert.SerializeObject(obj));
            // Receive
            string str = TCPHelper.Receive();

            Newtonsoft.Json.Linq.JArray o = (Newtonsoft.Json.Linq.JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(str);
            return(o.Value <bool>(0));
        }
Пример #6
0
        /// <summary>
        /// Génère le code pour la fonction de traitement des messages.
        /// </summary>
        public string ProcessRequest(string request, int clientId)
        {
            Newtonsoft.Json.Linq.JArray o = (Newtonsoft.Json.Linq.JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(request);
            int functionId = o.Value <int>(0);

            switch (functionId)
            {
            case 0:
                int arg0_0 = o[1].Value <int>(0);
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetShip(arg0_0)
                }));

            case 1:
                int arg1_0 = o[1].Value <int>(0);
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetShipPosition(arg1_0)
                }));

            case 2:
                int     arg2_0 = o[1].Value <int>(0);
                Vector2 arg2_1 = (Vector2)o[1][1].ToObject(typeof(Vector2));
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    SetShipPosition(arg2_0, arg2_1)
                }));

            case 3:
                int     arg3_0 = o[1].Value <int>(0);
                Vector2 arg3_1 = (Vector2)o[1][1].ToObject(typeof(Vector2));
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    MoveShip(arg3_0, arg3_1)
                }));
            }
            return("");
        }
Пример #7
0
        /// <summary>
        /// Génère le code pour la fonction de traitement des messages.
        /// </summary>
        public string ProcessRequest(string request, int clientId)
        {
            Newtonsoft.Json.Linq.JArray o = (Newtonsoft.Json.Linq.JArray)Newtonsoft.Json.JsonConvert.DeserializeObject(request);
            int functionId = o.Value <int>(0);

            switch (functionId)
            {
            case 0:
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetHero(clientId)
                }));

            case 1:
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetPosition(clientId)
                }));

            case 2:
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetMapView(clientId)
                }));

            case 3:
                Vector2 arg3_0 = (Vector2)o[1][0].ToObject(typeof(Vector2));
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    StartMoveTo(arg3_0, clientId)
                }));

            case 4:
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    IsAutoMoving(clientId)
                }));

            case 5:
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    EndMoveTo(clientId)
                }));

            case 6:
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetEntitiesInSight(clientId)
                }));

            case 7:
                int arg7_0 = o[1].Value <int>(0);
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetEntityById(arg7_0, clientId)
                }));

            case 8:
                int arg8_0 = o[1].Value <int>(0);
                SpellCastTargetInfoView arg8_1 = (SpellCastTargetInfoView)o[1][1].ToObject(typeof(SpellCastTargetInfoView));
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    UseSpell(arg8_0, arg8_1, clientId)
                }));

            case 9:
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetMode(clientId)
                }));

            case 10:
                int arg10_0 = o[1].Value <int>(0);
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetSpellCurrentLevelDescription(arg10_0, clientId)
                }));

            case 11:
                int arg11_0 = o[1].Value <int>(0);
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetSpell(arg11_0, clientId)
                }));

            case 12:
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetSpells(clientId)
                }));

            case 13:
                int arg13_0 = o[1].Value <int>(0);
                return(Newtonsoft.Json.JsonConvert.SerializeObject(new List <object>()
                {
                    GetHeroSpells(arg13_0, clientId)
                }));
            }
            return("");
        }