コード例 #1
0
        //Recieving information from client
        private void OnReceiveHost(IAsyncResult ar)
        {
            try
            {
                Socket.EndReceive(ar);
                var data = Data;
                Data = new byte[16384];
                Socket.BeginReceive(Data, 0, Data.Length, SocketFlags.None, new AsyncCallback(OnReceiveHost), null);

                var newData = new byte[data.Length - 1];
                Array.Copy(data, 1, newData, 0, data.Length - 1);
                switch (data[0])
                {
                case 2:
                    Player2 = Serializer.Deserialize(newData) as PlayerTurn;
                    Gm.ActualizeMap(Player2);
                    Gm.ActualizeCharacters();
                    CheckAndCalculateTurn();
                    break;

                case 3:
                    var message = Encoding.UTF8.GetString(newData);
                    Gm.ShowMessage(message);
                    break;

                default:
                    throw new SystemException("Got bad first byte");
                }
            }
            catch (SocketException)
            {
                Gm.EndOfGame();
            }
        }
コード例 #2
0
    private void OnTriggerEnter(Collider other)
    {
        //ANOTHER CAR ZONE
        if (other.gameObject.layer == 7)
        {
            ReduceSpeed();
            Gm.ReduceAllLevelOtherCarsSpeed();
            _km.OpenKeyboard();
            _uiManager.ShowWord();
            _soundManager.SetPitch(_soundManager.drivingSound, -0.1f);
            _soundManager.CreateSoundAndDestroy(_soundManager.slowDownSound, 1f, _camera.transform);
            Gm.TutorialGameInTime(1f);
        }

        //ANOTHER CAR
        if (other.gameObject.layer == 6)
        {
            Gm.LoseGame();
            NullifyVelocity();
            SetStartAnim(false);
            SetLoseAnim();
            _soundManager.Vibrate();
            _soundManager.CreateSoundAndDestroy(_soundManager.carSkidSound, 0.7f, _camera.transform);
            _soundManager.CreateSoundAndDestroy(_soundManager.hitSound, 1f, _camera.transform);
            _km.CloseKeyboard();
            other.GetComponent <OtherCarsController>().SetLoseAnim();
        }
    }
コード例 #3
0
    private void RemoveLastAbility()
    {
        if (!Gm.combatManager.IsAbilityQueueEmpty())
        {
            RemoveAbilityItemLock();
            Gm.combatManager.RemoveLastQueuedAbility();

            Gm.hudManager.commandInterface.ShowCompatibleCommands(Gm.combatManager, CurrentActor);

            if (Gm.combatManager.IsAbilityQueueEmpty())
            {
                Gm.hudManager.inputInfoInterface.ShowCommands(new Dictionary <string, string>
                {
                    { "WASD", "Browse commands" },
                    { "SPACE", "Enqueue command" },
                    { "E", "Close panel" }
                });
            }
        }
        else
        {
            EventManager <List <AbilityDetails> > .Invoke(EventType.OnAbilityQueueChanged, null);

            Gm.SwitchState(typeof(State_PlayerTurn_Move));
        }
    }
コード例 #4
0
ファイル: Cm.cs プロジェクト: taitoquic/Brackeys-Challenge
 void Solve()
 {
     if (c1.face.sprite == face.sprite)
     {
         p += 3;
         succes.Play();
         pairsThisLevel++;
         Reward(c1);
         Reward(this);
         Gm.CounterMinusOne(face.sprite);
         if (pairsThisLevel == Progress.PairsToEndLevel)
         {
             StartCoroutine(Gm.NextScene());
         }
     }
     else
     {
         p -= 1;
         fail.Play();
         c1.Resuma();
         Resuma();
     }
     c1      = null;
     sc.text = p.ToString();
 }
コード例 #5
0
 private void AdvanceToPerformanceState()
 {
     if (!Gm.combatManager.IsAbilityQueueEmpty())
     {
         // Gm.combatManager.ConfirmAbilityQueue();
         Gm.SwitchState(typeof(State_PlayerTurn_Performance));
     }
 }
コード例 #6
0
 protected override void Attack()
 {
     GetComponent <Animator>().SetTrigger("Spawn");
     Position = RotatePosition;
     Speed    = 0;
     attack   = false;
     Gm.RemoveLife(1);
     boss.notifyAttack();
 }
コード例 #7
0
    protected IEnumerator LaunchAttack(float delay)
    {
        spawn += 1;
        yield return(Gm.WaitFor(delay));

        if (IsInvisible)
        {
            spawn -= 1;
            yield break;
        }
        Spawn(3, 1);
    }
コード例 #8
0
    //public GameObject[] buttonRef;

    //[HideInInspector]
    //public List<CombinationHandler.Button> Combination = new List<CombinationHandler.Button>();
    //public int CombinationSize = 3;
    //public int Life = 2;
    //public float Speed = 0.1f;
    //public bool IsMoving = true;
    //public int NbrGold = 0;
    //[HideInInspector]
    //public Vector3 Position;
    //public float SpawnCooldown = 1000.0f;
    //public bool Died = false;

    //protected GameManager Gm;
    //protected Dictionary<CombinationHandler.Button, GameObject> ObjectToInstantiate = new Dictionary<CombinationHandler.Button, GameObject>();
    //protected BoxCollider boxCollider;
    //protected List<GameObject> ButtonsEnemy = new List<GameObject>();
    //protected GameObject EnemyLifeObj;

    //protected void Awake()
    //{
    //    ObjectToInstantiate[CombinationHandler.Button.BLUE] = Resources.Load<GameObject>("Prefabs/ButtonsEnemy/BlueButton");
    //    ObjectToInstantiate[CombinationHandler.Button.YELLOW] = Resources.Load<GameObject>("Prefabs/ButtonsEnemy/YellowButton");
    //    ObjectToInstantiate[CombinationHandler.Button.GREEN] = Resources.Load<GameObject>("Prefabs/ButtonsEnemy/GreenButton");
    //    ObjectToInstantiate[CombinationHandler.Button.RED] = Resources.Load<GameObject>("Prefabs/ButtonsEnemy/RedButton");
    //    EnemyLifeObj = Resources.Load<GameObject>("Prefabs/EnemyLife");
    //    boxCollider = GetComponent<BoxCollider>();
    //    Position = GetComponent<Transform>().position;
    //}

    //public virtual List<CombinationHandler.Button> getCombination()
    //{
    //    return Combination;
    //}

    //protected void Start()
    //{
    //    Gm = GameManager.instance;
    //}

    //void Start(List<CombinationHandler.Button> combination, int nbrGold, Vector3 position)
    //{
    //    Combination = combination;
    //    NbrGold = nbrGold;
    //    Position = position;
    //    Gm = GameManager.instance;
    //}

    //public override void Init(int nLife, int nGold, int nConbinationCount)
    //{
    //    this.Life = nLife;
    //    this.NbrGold = nGold;
    //    this.CombinationSize = nConbinationCount;
    //}

    protected override void Attack()
    {
        foreach (GameObject b in ButtonsEnemy)
        {
            b.SetActive(false);
        }
        EnemyLifeObj.SetActive(false);
        IsMoving = false;
        GetComponent <Animator>().SetTrigger("Attack");
        Gm.NotifyDie(gameObject, false);

        Gm.RemoveLife(1);
    }
コード例 #9
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            DestroyObject(gameObject);
        }
        // Do not destroy this game object:

        DontDestroyOnLoad(gameObject);
    }
コード例 #10
0
    private bool TryToAttackTarget(Combatant target)
    {
        if (!_hasAttacked && CurrentActor.HasAbilityThatCanReach(CurrentActor.point, target.point))
        {
            _hasAttacked = true;
            Gm.combatManager.EnqueueCommand(new AbilityDetails(CurrentActor.GetCurrentlyPerformableAbilities()[0], CurrentActor, new List <GridObject> {
                target
            }));
            Gm.SwitchState(typeof(State_EnemyTurn_Performance), 0.5f);

            return(true);
        }

        return(false);
    }
コード例 #11
0
        private void Start()
        {
            print("hey");
            gm = GameObject.FindGameObjectWithTag("GameController").GetComponent <Gm>();
            setStats();
            // get the transform of the main camera
            if (Camera.main != null)
            {
                m_Cam = Camera.main.transform;
            }
            else
            {
                Debug.LogWarning(
                    "Warning: no main camera found. Third person character needs a Camera tagged \"MainCamera\", for camera-relative controls.");
                // we use self-relative controls in this case, which probably isn't what the user wants, but hey, we warned them!
            }

            // get the third person character ( this should never be null due to require component )
            m_Character = GetComponent <ThirdPersonCharacter>();

            if (inputManagerDatabase == null)
            {
                inputManagerDatabase = (InputManager)Resources.Load("InputManager");
            }

            if (inventory != null)
            {
                mainInventory = inventory.GetComponent <Inventory>();
            }
            if (characterSystem != null)
            {
                characterSystemInventory = characterSystem.GetComponent <Inventory>();
            }

            maxDamage     = 30;
            currentDamage = 10;

            if (battle)
            {
                defeat = GameObject.FindGameObjectWithTag("endBattle");
                defeat.GetComponent <Text>().text = "Defeat!";
                defeat.SetActive(false);
                buttonContinue = GameObject.FindGameObjectWithTag("buttonContinue");
                buttonContinue.SetActive(false);
                imageItem = GameObject.FindGameObjectWithTag("image").gameObject;
                imageItem.SetActive(false);
            }
        }
コード例 #12
0
        //if have both player declaration calculate turn show them and send results to client
        private void CheckAndCalculateTurn()
        {
            if (Player1 == null || Player2 == null)
            {
                return;
            }

            Gm.ShowMessage("Calculating turn");
            var turnResults = TurnLogic.ResolveTurn(Player1, Player2, Gm.Map);

            Player1 = null;
            Player2 = null;
            SendData(1, Serializer.Serialize(Gm.Map));
            SendData(0, Serializer.Serialize(turnResults));
            Gm.ShowResultsFromGc(turnResults);
        }
コード例 #13
0
    protected IEnumerator chooseAttack(float delay)
    {
        yield return(Gm.WaitFor(delay));

        while (true)
        {
            foreach (BlackPawnMinon m in minions)
            {
                if (m.Position.y < Position.y)
                {
                    m.launchAttack();
                    yield break;
                }
            }
            yield return(Gm.WaitFor(0.2f));
        }
    }
コード例 #14
0
    // Initiates the Knight class
    public void InitiateKnight()
    {
        // Sets the Game Manager
        Gm = GameObject.Find("Game Manager");
        GM = Gm.GetComponent <GameManager>();

        // Sets the Knight's class
        UnitClass = GetUnitClass(this.gameObject);
        // Knight has medium health
        MaxHealth = 50;
        Health    = 50;
        // Knight deals medium damage
        AttackDamage = 10;
        // Knight has close range
        Range = 3;
        // Knight has fast attack speed
        AttackSpeed = 1.5f; // 1 Second

        agent = this.gameObject.GetComponent <NavMeshAgent>();
    }
コード例 #15
0
ファイル: BattleBegin.cs プロジェクト: snafua/TrollsAndGods
        /// <summary>
        /// Executing the action, beginning the battle, only showing the battle if the player is a part of the battle.
        /// </summary>
        public override void execute()
        {
            //todo not show battle if not involved
            Reaction reaction = Gm.Reactions[pos.x, pos.y];

            if (reaction.HasPreReact())
            {
                reaction = reaction.PreReaction;
            }
            if (reaction.GetType() == typeof(HeroMeetReact))
            {
                HeroMeetReact hmr = (HeroMeetReact)reaction;
                Gm.enterCombat(15, 11, Gm.getPlayer(playerID).Heroes[heroID], hmr.Hero);
            }
            else
            {
                UnitReaction ur = (UnitReaction)reaction;
                Gm.enterCombat(15, 11, Gm.getPlayer(playerID).Heroes[heroID], ur.Units, true);
            }
        }
コード例 #16
0
    // Initiates the Pikeman class
    public void InitiatePikeman()
    {
        // Sets the Game Manager
        Gm = GameObject.Find("Game Manager");
        GM = Gm.GetComponent <GameManager>();

        // Sets the Knight's class
        UnitClass = GetUnitClass(this.gameObject);
        // Pikeman has high health
        MaxHealth = 75;
        Health    = 75;
        // Pikeman deals low damage
        AttackDamage = 5;
        // Pikeman has close range
        Range = 3;
        // Pikeman has low attack speed
        AttackSpeed = 4f; // 4 Seconds

        agent = this.gameObject.GetComponent <NavMeshAgent>();
    }
コード例 #17
0
    protected IEnumerator Wait()
    {
        foreach (GameObject b in ButtonsEnemy)
        {
            b.SetActive(false);
        }
        EnemyLifeObj.SetActive(false);
        Rend.enabled = false;
        float spd = Speed;

        Speed = 0;
        yield return(Gm.WaitFor(1.0f));

        Speed = spd;
        foreach (GameObject b in ButtonsEnemy)
        {
            b.SetActive(true);
        }
        EnemyLifeObj.SetActive(true);
        Rend.enabled = true;
    }
コード例 #18
0
    // Initiates the Wizard class
    public void InitiateWizard()
    {
        // Sets the Game Manager
        Gm = GameObject.Find("Game Manager");
        GM = Gm.GetComponent <GameManager>();

        // Sets the Knight's class
        UnitClass = GetUnitClass(this.gameObject);
        // Wizard has low health
        MaxHealth = 25;
        Health    = 25;
        // Wizard deals medium damage
        AttackDamage = 7.5f;
        // Wizard has medium range
        Range = 25;
        // Wizard has medium attack speed
        AttackSpeed = 3f; // 3 Seconds
        // Spells fly slower
        ProjectileSpeed = 50;

        agent = this.gameObject.GetComponent <NavMeshAgent>();
    }
コード例 #19
0
    // Initiates the Archer class
    public void InitiateArcher()
    {
        // Sets the Game Manager
        Gm = GameObject.Find("Game Manager");
        GM = Gm.GetComponent <GameManager>();

        // Sets the Knight's class
        UnitClass = GetUnitClass(this.gameObject);
        // Archer has low health
        MaxHealth = 25;
        Health    = 25;
        // Archer deals high damage
        AttackDamage = 20;
        // Archer has long range
        Range = 40;
        // Archer has low attack speed (Reload time)
        AttackSpeed = 5; // 5 Seconds
        // Arrows fly fast
        ProjectileSpeed = 100;

        agent = this.gameObject.GetComponent <NavMeshAgent>();
    }
コード例 #20
0
        //Recieving information from host
        private void OnReceiveClient(IAsyncResult ar)
        {
            try
            {
                Socket.EndReceive(ar);
                var data = Data;
                Data = new byte[16384];
                Socket.BeginReceive(Data, 0, Data.Length, SocketFlags.None, new AsyncCallback(OnReceiveClient), null);

                var newData = new byte[data.Length - 1];
                Array.Copy(data, 1, newData, 0, data.Length - 1);
                switch (data[0])
                {
                case 0:
                    var results = Serializer.Deserialize(newData) as TurnResults;
                    Gm.ShowResultsFromGc(results);
                    break;

                case 1:
                    var map = Serializer.Deserialize(newData) as Map;
                    Gm.Map = map;
                    Gm.ActualizeCharacters();
                    break;

                case 3:
                    var message = Encoding.UTF8.GetString(newData);
                    Gm.ShowMessage(message);
                    break;

                default:
                    throw new SystemException("Got bad first byte");
                }
            }
            catch (SocketException)
            {
                Gm.EndOfGame();
            }
        }
コード例 #21
0
 private void ConfirmTarget()
 {
     Gm.combatManager.EnqueueCommand(new AbilityDetails(_currentCommand, CurrentActor, DetermineTargets()));
     Gm.SwitchState(typeof(State_PlayerTurn_PickAbility));
 }
コード例 #22
0
 private void SwitchToAbilitySelectionState()
 {
     Gm.SwitchState(typeof(State_PlayerTurn_PickAbility));
 }
コード例 #23
0
 private void SwitchToInventoryState()
 {
     Gm.SwitchState(typeof(State_PlayerTurn_Inventory));
 }
コード例 #24
0
ファイル: Query.cs プロジェクト: rhalf/AtsTqatPro
        public void insertTrackerData (Tracker tracker, Gm gm) {
            try {
                mysqlConnection.Open();

                string sql =
                    "INSERT INTO " +
                    "trk_" + tracker.DatabaseName + ".gps_" + tracker.DatabaseName +
                    "(gm_time,gm_lat,gm_lng,gm_speed,gm_ori,gm_mileage,gm_data,gm_lasttime) " +
                    "VALUES(@TimeStamp,@Latitude,@Longitude,@Speed,@Orientation,@Mileage,@Data,@LastTime)";

                MySqlCommand mySqlCommand = new MySqlCommand(sql, mysqlConnection);
                mySqlCommand.Parameters.AddWithValue("@TimeStamp", gm.TimeStamp);
                mySqlCommand.Parameters.AddWithValue("@Latitude", gm.Latitude);
                mySqlCommand.Parameters.AddWithValue("@Longitude", gm.Longitude);
                mySqlCommand.Parameters.AddWithValue("@Speed", gm.Speed);
                mySqlCommand.Parameters.AddWithValue("@Orientation", gm.Orientation);
                mySqlCommand.Parameters.AddWithValue("@Mileage", gm.Mileage);
                mySqlCommand.Parameters.AddWithValue("@Data", gm.Data);
                mySqlCommand.Parameters.AddWithValue("@LastTime", gm.LastTime);

                if (mySqlCommand.ExecuteNonQuery() != 1) {
                    throw new Exception("Error on Insert..");
                }

            } catch (MySqlException mySqlException) {
                throw new QueryException(1, mySqlException.Message);
            } catch (QueryException queryException) {
                throw queryException;
            } catch (Exception exception) {
                throw new QueryException(1, exception.Message);
            } finally {
                mysqlConnection.Close();
            }
        }
コード例 #25
0
        protected override void Communicate(TcpTracker tcpTracker)
        {
            Gm gm = null;
            Byte[] bufferIn = new Byte[256];
            TcpClient tcpClient = tcpTracker.TcpClient;
            String dataOut = String.Empty;

            try {
                //do {
                NetworkStream networkStream = tcpClient.GetStream();

                //------------------------------------------------Receive message
                //Communication 1
                Array.Clear(bufferIn, 0, bufferIn.Length);
                Int32 count = networkStream.Read(bufferIn, 0, bufferIn.Length);
                base.PacketReceived++;
                base.ByteReceived += count;
                Byte[] incomingBytes = new Byte[count];
                Array.Copy(bufferIn, incomingBytes, count);

                if (incomingBytes[0] != 0x00 || incomingBytes[1] != 0x0f) {
                    return;
                    //throw new GmException(GmException.UNKNOWN_PROTOCOL, "");
                }

                gm = new Gm();
                gm.Unit = ASCIIEncoding.UTF8.GetString(incomingBytes, 2, incomingBytes.Length - 2);
                send(networkStream, new byte[] { 0x01 });
                dataOut = "0x01";

                //Communication 2
                Array.Clear(bufferIn, 0, bufferIn.Length);
                count = networkStream.Read(bufferIn, 0, bufferIn.Length);
                base.PacketReceived++;
                base.ByteReceived += count;
                incomingBytes = new Byte[count];
                Array.Copy(bufferIn, incomingBytes, count);

                if (!Teltonika.ParseGm(incomingBytes, ref gm)) {
                    return;
                }

                //Communication 3
                byte[] response = new byte[] { (byte)gm.RecordCount, 0x00, 0x00, 0x00 };
                send(networkStream, response);
                dataOut = "0x000000" + gm.RecordCount.ToString();

                //------------------------------------------------Send message if theres any
                //if (this.BufferOut != null) {
                //    if (this.BufferOut.ContainsKey(gm.Unit)) {
                //        if (this.BufferOut.ContainsKey(gm.Unit)) {
                //            String[] command;
                //            if (this.BufferOut.TryRemove(gm.Unit, out command)) {
                //                dataOut = Teltonika.GenerateCommand(command, gm.Identifier);
                //                send(networkStream, ASCIIEncoding.UTF8.GetBytes(dataOut));
                //            }
                //        }
                //    }
                //}
                //base.triggerEvent(new Log(BitConverter.ToString(incomingBytes).Replace("-", ""), LogType.FM1100));

                base.triggerDataReceived(gm);
                tcpTracker.Imei = gm.Unit;
                tcpTracker.DataIn = gm.Raw;
                tcpTracker.DataOut = dataOut;
                tcpTracker.DateTime = DateTime.Now;

                this.TcpClients.TrackersCount = countTrackers(this.TcpClients);
                //} while (tcpClient.Connected);

            } catch (GmException gmException) {
                triggerEvent(new Log(gmException.Imei + " : " + gmException.Description, LogType.FM1100));
            } catch (Exception exception) {
                triggerEvent(new Log(exception.Message, LogType.SERVER));
            } finally {
                if (!String.IsNullOrEmpty(gm.Unit)) {
                    tcpTracker.Imei = "";
                    tcpTracker.DataIn = "";
                    tcpTracker.DataOut = "";
                    tcpTracker.DateTime = DateTime.Now;
                    this.TcpClients.TrackersCount = countTrackers(this.TcpClients);
                }
                tcpClient.Close();
            }
        }
コード例 #26
0
ファイル: BattleEnd.cs プロジェクト: snafua/TrollsAndGods
 /// <summary>
 /// Executes the action, Ending the battle.
 /// </summary>
 public override void execute()
 {
     //todo test
     Gm.exitCombat(winner);
 }
コード例 #27
0
ファイル: Teltonika.cs プロジェクト: rhalf/AtsGpsSocket
        public static bool ParseGm(byte[] raw, ref Gm gm)
        {
            //00000000000000C50802000001520D315578011EB133890F0E74C40023010809000042160B010002000300B300B4004
            //501F00050041503C800EF000709001BB50010B6000C4225C6180000CD5494CE008E03C700000000F10000A6CE480000
            //0000014E0000000000000000000001520BDD0C30011EB1355B0F0E8061001000A80C000042160B010002000300B300B
            //4004501F00050041504C800EF000709001BB50014B60009422585180000CD53C3CE008E03C700000000F10000A6CE48
            //00000000014E000000000000000002000080C5

            //00000000000000C5
            //08                ->  Unit Identifier     -> 8
            //02                ->  Record Count        -> 9

            //Record 1
            //000001520D315578  ->  Timestamp           -> 10
            //01                ->  Priority            -> 18
            //1EB13389          ->  Longitude           -> 19
            //0F0E74C4          ->  Latitude            -> 23
            //0023              ->  Altitude            -> 27
            //0108              ->  Angle               -> 29
            //09                ->  Visible Satellites  -> 31
            //0000              ->  Speed               -> 32

            //IO
            //42
            //16
            //0B
            //01
            //00
            //02
            //00
            //03
            //00
            //B3
            //00
            //B4

            //004501F0
            //00

            //2nd record
            //50041503C800EF000709001BB50010B6000C4225C6180000CD5494CE008E03C700000000F10000A6CE4800000000014
            //E0000000000000000000001520BDD0C30011EB1355B0F0E8061001000A80C000042160B010002000300B300B4004501
            //F00050041504C800EF000709001BB50014B60009422585180000CD53C3CE008E03C700000000F10000A6CE480000000
            //0014E000000000000000002000080C5

            //gm.Latitude
            //gm.Longitude
            //gm.Orientation
            //==============================================================================================

            //throw new Exception(BitConverter.ToString(raw).Replace("-",""));

            byte[] value = null;

            try {
                //value = new byte[] { raw[9] };
                gm.RecordCount = raw[9];

                value = new byte[] { raw[17], raw[16], raw[15], raw[14], raw[13], raw[12], raw[11], raw[10] };
                long timeStamp = BitConverter.ToInt64(value, 0) / 1000;
                gm.TimeStamp = timeStamp.ToString();

                value = new byte[] { raw[22], raw[21], raw[20], raw[19] };
                int longitude = BitConverter.ToInt32(value, 0);
                gm.Longitude = (longitude / 10000000d).ToString();

                value = new byte[] { raw[26], raw[25], raw[24], raw[23] };
                int latitude = BitConverter.ToInt32(value, 0);
                gm.Latitude = (latitude / 10000000d).ToString();

                value = new byte[] { raw[28], raw[27] };
                string altitude = BitConverter.ToInt16(value, 0).ToString();

                value = new byte[] { raw[30], raw[29] };
                gm.Orientation = BitConverter.ToInt16(value, 0).ToString();

                value = new byte[] { raw[31] };
                int gpsSatellites = value[0];

                value = new byte[] { raw[33], raw[32] };
                gm.Speed = BitConverter.ToInt16(value, 0).ToString();

                //==========================IO
                // events
                value = new byte[] { raw[34] };
                int events = value[0];

                //elements in record
                value = new byte[] { raw[35] };
                int ioElementTotalCount = value[0];

                int indexStart = 0;
                int indexOn = 0;

                List<Io> ioArray1b = new List<Io>();
                List<Io> ioArray2b = new List<Io>();
                List<Io> ioArray4b = new List<Io>();
                List<Io> ioArray8b = new List<Io>();

                #region elements1b
                value = new byte[] { raw[36] };
                int ioElementCount1b = value[0];

                indexStart = 37;
                indexOn = 0;

                for (int index = 0; index < ioElementCount1b; index++) {
                    indexOn = indexStart + (index * 2);
                    ioArray1b.Add(
                        new Io() {
                            Id = raw[indexOn],
                            Value = raw[indexOn + 1]
                        });
                }
                //throw new Exception(JsonConvert.SerializeObject(ioArray1b));
                #endregion  elements1b

                #region elements2b

                value = new byte[] { raw[indexOn + 2] };
                int ioElementCount2b = value[0];

                indexStart = indexOn + 3;
                indexOn = 0;

                for (int index = 0; index < ioElementCount2b; index++) {
                    indexOn = indexStart + (index * 3);
                    ioArray2b.Add(
                        new Io() {
                            Id = raw[indexOn],
                            Value = BitConverter.ToInt16(
                                new byte[] {
                                    raw[indexOn + 2],
                                    raw[indexOn + 1]
                                }, 0)
                        });
                }
                //throw new Exception(JsonConvert.SerializeObject(ioArray2b));
                #endregion elements2b
                #region elements4b

                value = new byte[] { raw[indexOn + 3] };
                int ioElementCount4b = value[0];

                indexStart = indexOn + 4;
                indexOn = 0;

                for (int index = 0; index < ioElementCount4b; index++) {
                    indexOn = indexStart + (index * 5);
                    ioArray4b.Add(
                        new Io() {
                            Id = raw[indexOn],
                            Value = BitConverter.ToInt32(
                                new byte[] {
                                    raw[indexOn + 4],
                                    raw[indexOn + 3],
                                    raw[indexOn + 2],
                                    raw[indexOn + 1]
                                }, 0)
                        });
                }
                //throw new Exception(JsonConvert.SerializeObject(ioArray4b));

                #endregion elements4b

                //===============================
                int acc = 0;
                foreach (Io io in ioArray1b) {
                    //EF - Ignition IO ID 239
                    if (io.Id == 0xEF)
                        acc = io.Value;
                }

                int mileAge = 0;
                foreach (Io io in ioArray4b) {
                    //EF - Odometer IO ID 199
                    if (io.Id == 0xC7)
                        mileAge = io.Value;
                }
                //===============================

                gm.Mileage = mileAge.ToString();

                StringBuilder sb = new StringBuilder();

                sb.Append((gpsSatellites > 0) ? "1" : "0");
                sb.Append(",35");
                sb.Append("," + gpsSatellites.ToString());
                sb.Append(",26,");
                sb.Append(mileAge.ToString());
                sb.Append(",1.0,4,2156297,427|1|2582|5C1E,");
                sb.Append("0,0,0,0,0,0,0,0,");
                sb.Append("0," + acc.ToString() + ",0,0,0,0,0,0,");
                sb.Append("0004,0000,0000,0847,0000,00000001");

                gm.Data = sb.ToString();

                gm.LastTime = "0";

                StringBuilder sb1 = new StringBuilder();
                foreach (Io io in ioArray1b) {
                    sb1.Append(io.Id.ToString() + ":" + io.Value.ToString() + ",");
                }

                gm.Raw = sb1.ToString();//BitConverter.ToString(raw).Replace("-", "");

            } catch (Exception exception) {
                throw new GmException(GmException.UNKNOWN_PROTOCOL, gm.Unit, exception);
            }
            return true;
        }
コード例 #28
0
 private void ReturnToAbilityState()
 {
     Gm.SwitchState(typeof(State_PlayerTurn_PickAbility));
 }
コード例 #29
0
ファイル: Meitrack.cs プロジェクト: rhalf/AtsGpsSocket
        public static bool ParseGm(byte[] raw, int length, out Gm gm)
        {
            String packet = null;
            String[] packetArray = null;
            gm = new Gm();

            if (raw[0] == 36 && raw[1] == 36) {
                #region Validate
                //Device    1           2   3       4       5           6       7  8 9 10 11 12  13  14         15          16         17           18                19    20
                //@@Q25,353358017784062,A10,35,24.963245,51.598091,151111064417,A,10,13,0,28,0.9,0,20164489,15062657,427|1|238E|6375,0200,0013|0000|0000|0A8B|0842,00000039,*6A

                //1,35,9,24,1450984,1.1,8,484707,427 | 2 | 008F | 2DE9,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0003,0000,0000,0A68,0432,00000001
                try {
                    packet = ASCIIEncoding.UTF8.GetString(raw, 0, length).Trim(new char[] { '\0', '\r', '\n' });
                    packetArray = packet.Split(',');
                    gm.Raw = packet;
                    gm.Unit = packetArray[1];
                    gm.Identifier = raw[2];
                    if (packetArray[3].Contains("OK")) {
                        return false;
                    }
                } catch (Exception exception) {
                    throw new GmException(GmException.UNKNOWN_PROTOCOL, exception.Message, packet);
                }

                //if (!Meitrack.CheckSum(ASCIIEncoding.UTF8.GetBytes(packet))) {
                //    throw new GmException(GmException.WRONG_CHECKSUM, gm.Unit, packet);
                //}

                //if (!Meitrack.CheckDataLength(packet)) {
                //    throw new GmException(GmException.WRONG_DATA_LENGTH, gm.Unit, packet);
                //}
                #endregion

                try {
                    gm.TimeStamp = Gm.toUnixTimestamp(packetArray[6]).ToString();
                    gm.Latitude = packetArray[4];
                    gm.Longitude = packetArray[5];
                    gm.Speed = packetArray[10];
                    gm.Orientation = packetArray[11];
                    gm.Mileage = Math.Round((Double.Parse(packetArray[14]) / 1000d), 2).ToString();
                } catch {
                    throw new GmException(GmException.UNKNOWN_PROTOCOL, "Parsing Error on Primary Properties.", packet);
                }

                //1,			            //GPS signal status
                //35,			            //Event code(Decimal)
                //11,			            //Number of satellites(Decimal)
                //26,			            //GSM signal status(Decimal)
                //17160691, 		        //Mileage(Decimal)unit: meter
                //0.7, 			            //hpos accuracy(Decimal)
                //18, 			            //Altitude(Decimal)unit: meter
                //18661240, 		        //Run time(Decimal)unit: second
                //427|2|0078|283F, 	        //Base station information(binary|binary|hex|hex)           (8)
                //==============================================0200
                //0,0,0,0,0,0,0,0,          //Io port lowbyte (low bit start from left)                 (9)
                //0,1,0,0,0,0,0,0,          //Io port lowbyte (low bit start from left)                 (17)
                //==============================================
                //000B,0000,0000,0A6E,0434, //Analog input value                                        (25)
                //00000001 		            //System mark

                //gm_id = 10682
                //gm_time = 1428992007(1)
                //gm_lat = 25.891435(2)
                //gm_lng = 51.508528(3)
                //gm_speed = 0(4)
                //gm_ori = 117(5)
                //gm_mileage = 3627.813(6)
                //gm_data = 1,35,11,26,6596078,1.0,4,2156297,427|1|2582|5C1E,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0004,0000,0000,0847,0000,00000001(7)

                StringBuilder sb = new StringBuilder();
                try {
                    if (packetArray[7].Equals("V")) {
                        sb.Append("0,");
                    } else {
                        sb.Append("1,");
                    }

                    sb.Append(packetArray[3] + ","); //Event code(Decimal)
                    sb.Append(packetArray[8] + ","); //Number of satellites(Decimal)
                    sb.Append(packetArray[9] + ","); //GSM signal status(Decimal)
                    sb.Append(packetArray[14] + ","); //Mileage(Decimal)unit: meter
                    sb.Append(packetArray[12] + ","); //hpos accuracy(Decimal)
                    sb.Append(packetArray[13] + ","); //Altitude(Decimal)unit: meter
                    sb.Append(packetArray[15] + ","); //Run time(Decimal)unit: second
                    sb.Append(packetArray[16] + ","); //Base station information(binary|binary|hex|hex)           (8)
                } catch {
                    throw new GmException(GmException.UNKNOWN_PROTOCOL, "Parsing Error on Secondary Properties.", packet);
                }

                int[] aIo = new int[16];

                try {

                    //Int32 io = Int32.Parse(packetArray[17], System.Globalization.NumberStyles.HexNumber);

                    //for (int index = 0; index < 16; index++) {
                    //    if (((io >> (index)) & 1) == 1) {
                    //        sb.Append("1,");
                    //    } else {
                    //        sb.Append("0,");
                    //    }
                    //}

                    Int32 io = Int32.Parse(packetArray[17], System.Globalization.NumberStyles.HexNumber);

                    for (int index = 0; index < 16; index++) {
                        if (((io >> (index)) & 1) == 1) {
                            aIo[index] = 1;
                        } else {
                            aIo[index] = 0;
                        }
                    }

                    if (aIo[10] == 1) {
                        aIo[9] = 1;
                    }

                    for (int index = 0; index < 16; index++) {
                        if (aIo[index] == 1) {
                            sb.Append("1,");
                        } else {
                            sb.Append("0,");
                        }
                    }
                } catch {
                    for (int index = 0; index < 16; index++) {
                        sb.Append("0,");
                    }
                }
                String[] analog = packetArray[18].Split('|');
                sb.Append((String.IsNullOrEmpty(analog[0]) ? "0" : analog[0]) + ",");
                sb.Append((String.IsNullOrEmpty(analog[1]) ? "0" : analog[1]) + ",");
                sb.Append((String.IsNullOrEmpty(analog[2]) ? "0" : analog[2]) + ",");
                sb.Append((String.IsNullOrEmpty(analog[3]) ? "0" : analog[3]) + ",");
                sb.Append((String.IsNullOrEmpty(analog[4]) ? "0" : analog[4]) + ",");
                sb.Append("00000001");

                gm.Data = sb.ToString();
                gm.LastTime = "0";
                return true;

            } else {
                return false;
            }
        }
コード例 #30
0
 private void SwitchToMoveState()
 {
     // Gm.combatManager.ClearAbilityQueue();
     Gm.SwitchState(typeof(State_PlayerTurn_Move));
 }
コード例 #31
0
 void Awake()
 {
     instance = this;
     hp       = 3;
     remain   = 10;
 }