public static void ProcessPacket(FastList<byte> packet)
        {
            if (packet == null || packet.Count < 4) {
                throw new System.Exception("Packet is null or not valid length");
            }
            int frameCount = BitConverter.ToInt32 (packet.innerArray, 0);
            int index = 4;

            if (FrameManager.HasFrame (frameCount) == false) {
                Frame frame = new Frame ();

                if (packet.Count > 4) {
                    RecordedBytes.AddRange (BitConverter.GetBytes ((ushort)packet.Count));
                    RecordedBytes.AddRange (packet);
                    while (index < packet.Count) {
                        Command com = new Command ();
                        index += com.Reconstruct (packet.innerArray, index);
                        frame.AddCommand (com);
                    }
                    if (frameCount > LastCommandedFrameCount) {
                        LastCommandedFrameCount = frameCount;
                    }
                }
                FrameManager.AddFrame (frameCount, frame);

            } else {

            }
        }
        public static void Simulate()
        {
            if (Offline) {
                    ReceivedBytes.AddRange (BitConverter.GetBytes (LockstepManager.FrameCount));
                    for (i = 0; i < OutCommands.Count; i++) {
                        ReceivedBytes.AddRange (OutCommands [i].Serialized);
                    }
                    AllReceivedBytes.AddRange (BitConverter.GetBytes (ReceivedBytes.Count));
                    AllReceivedBytes.AddRange (ReceivedBytes);
            } else {

            }

            int frameCount = BitConverter.ToInt32 (ReceivedBytes.innerArray, 0);
            Index = 4;

            FrameManager.EnsureCapacity (frameCount + 1);

            Frame frame;
            if (!FrameManager.HasFrame [frameCount]) {
                frame = new Frame ();
                FrameManager.AddFrame (frameCount, frame);

                while (Index < ReceivedBytes.Count) {
                    Command com = new Command ();
                    Index += com.Reconstruct (ReceivedBytes.innerArray, Index);
                    frame.AddCommand (com);
                }
            }

            ReceivedBytes.FastClear ();
            OutCommands.FastClear ();
        }
示例#3
0
 protected override void OnExecute(Command com)
 {
     if (com.HasCount && com.HasTarget)
     {
         Tiles[com.Target].Execute (com);
     }
 }
        public static void SendCommand(Command com)
        {
            if (sendState == SendState.None) {
                return;
            }

            OutCommands.Add (com);
        }
 public void AddCommand(Command com)
 {
     if (Commands == null)
     {
         Commands = new FastList<Command>(2);
     }
     Commands.Add(com);
 }
 public void AddCommands(Command[] coms, int startIndex, int count)
 {
     if (Commands == null)
     {
         Commands = new FastList<Command> ();
     }
     Commands.AddRange (coms,startIndex,count);
 }
 private Command _GenerateFireCommand(bool startShoot)
 {
     Command com = new Command(startShoot ? StartShootCode : EndShootCode, this.Agent.Controller.ControllerID);
     if (startShoot) {
         com.Add<DefaultData> (new DefaultData(DataType.Int,LockstepManager.FrameCount));
     }
     return com;
 }
        public static void Visualize()
        {
            SelectionManager.Update ();
            if (Input.GetMouseButtonDown(1))
            {

                Command com = new Command(agentControllers[0].ControllerID,InputCode.M);
                Selection select = new Selection();
                select.SerializeFromSelectionManager ();
                com.Select = select;
                com.Position = new Vector2d(SelectionManager.MouseWorldPosition);
                NetworkManager.SendCommand (com);
            }
        }
        protected override void OnRawExecute(Command com)
        {
            if (com.InputCode == StartShootCode || com.InputCode == EndShootCode)
            {
                
                if (com.InputCode == StartShootCode)
                {

                    int comFrame = (int)com.GetData<DefaultData>().Value;
                    PassedFrames = LockstepManager.FrameCount - comFrame;
                    uint currentShot = (uint)com.GetData<DefaultData>(1).Value;
                    if (this.LatencyProjectiles.ContainsKey(currentShot)) {
                        ProjectileManager.EndProjectile(this.LatencyProjectiles[currentShot]);
                    }

                    this.IsFiring = true;
                    this.CheckFire();

                }
                else if (com.InputCode == EndShootCode)
                    this.IsFiring = false;
            }
        }
        public bool GenerateFireCommand(bool startShoot, out Command com)
        {
            if (startShoot)
            {
                com = _GenerateFireCommand(true);
                com.Add<DefaultData> (new DefaultData(DataType.UInt,CurrentShotID));
                LSProjectile projectile = ProjectileManager.NDCreateAndFire (
                    this.ProjCode,
                    ProjectileStartPosition,
                    Turner.GenerateForwards(Turner.CameraController.transform.rotation));

                LatencyProjectiles.Add(CurrentShotID,projectile);
                CurrentShotID++;
                return true;
            } else
            {
                if (ShootType == ShootType.Chain)
                {
                    com = _GenerateFireCommand(false);
                    return true;
                }
            }
            com = null;

            return false;
        }
示例#11
0
        protected override void OnExecute(Command com)
        {
            Agent.StopCast(this.ID);

            if (com.HasPosition || com.HasTarget)
            {
                if (com.HasPosition && CanMove)
                {

                    if (HasTarget)
                    {
                        cachedMove.RegisterGroup(false);
                    } else
                    {
                        cachedMove.RegisterGroup();
                    }

                    isAttackMoving = true;
                    isFocused = false;

                } else if (com.HasTarget)
                {

                    isFocused = true;
                    isAttackMoving = false;
                    LSAgent tempTarget;
                    AgentController.TryGetAgent(com.Target, out tempTarget);
                    Engage(tempTarget);
                }
            }
        }
 private static void Send(Command com)
 {
     IsGathering = false;
     PlayerManager.SendCommand(com);
 }
        public void Execute(Command com)
        {
            if (com.LeInput == InputCode.Spawn) {
                for (int i = 0; i < com.Count; i++) {
                    LSAgent agent = CreateAgent((AgentCode)com.Target, com.Position);
                }
                return;
            }

            if (com.HasGroupID) {
                /*var group = AgentGroupController.GetGroup(com.GroupID);
                if (group .IsNotNull ()) {
                    for (i = 0; i < group.Agents.Count; i++) {
                        group.Agents[i].Execute(com);
                    }
                }*/
            }
            else {
                if (com.HasSelect == false) com.Select = previousSelection;
                previousSelection = com.Select;
            }

            BehaviourHelper.GlobalExecute (com);
            for (int i = 0; i < com.Select.selectedAgentLocalIDs.Count; i++) {
                ushort selectedAgentID = com.Select.selectedAgentLocalIDs[i];
                if (LocalAgentActive[selectedAgentID])
                {
                    LocalAgents[selectedAgentID].Execute(com);
                }
            }
        }
 public void Execute(Command com)
 {
     OnExecute(com);
 }
        public static void Simulate()
        {
            if (IterationCount == 0) {
                switch (sendState) {
                case SendState.Autosend:
                    ReceivedBytes.AddRange (BitConverter.GetBytes (LockstepManager.FrameCount));
                    for (i = 0; i < OutCommands.Count; i++) {
                        ReceivedBytes.AddRange (OutCommands [i].Serialized);
                    }
                    break;
                }

                if (ReceivedBytes.Count < 4)
                    return;

                int frameCount = BitConverter.ToInt32 (ReceivedBytes.innerArray, 0);
                Index = 4;

                FrameManager.EnsureCapacity (frameCount + 1);

                Frame frame;
                if (!FrameManager.HasFrame [frameCount]) {
                    ReceivedFrameCount++;
                    if (ReceivedBytes.Count > 4) {

                        RecordedBytes.AddRange (BitConverter.GetBytes ((ushort)ReceivedBytes.Count));
                        RecordedBytes.AddRange (ReceivedBytes);
                        LastRecordedFrame = ReceivedFrameCount;
                    }

                    frame = new Frame ();
                    FrameManager.AddFrame (frameCount, frame);

                    while (Index < ReceivedBytes.Count) {
                        Command com = new Command ();
                        Index += com.Reconstruct (ReceivedBytes.innerArray, Index);
                        frame.AddCommand (com);
                    }
                }

                ReceivedBytes.FastClear ();
                OutCommands.FastClear ();

                IterationCount = LockstepManager.NetworkingIterationSpread - 1;
            } else {
                IterationCount--;
                FrameManager.AddFrame (LockstepManager.FrameCount, new Frame ());
            }
        }
 protected override void OnExecute(Command com)
 {
     Execute(com);
 }
 public static void Execute(Command com)
 {
     if (com.HasPosition)
     {
         CreateGroup(com);
     }
 }
        public static MovementGroup CreateGroup(Command com)
        {
            MovementGroup moveGroup = pooledGroups.Count > 0 ? pooledGroups.Pop() : new MovementGroup();

            moveGroup.indexID = activeGroups.Add(moveGroup);
            LastCreatedGroup = moveGroup;
            moveGroup.Initialize(com);
            return moveGroup;
        }
 public void Initialize(Command com)
 {
     Destination = com.Position;
     calculatedBehaviors = false;
     movers = new FastList<Move>(com.Select.selectedAgentLocalIDs.Count);
 }
 public static void SendCommand(Command com)
 {
     com.Select = new Selection ();
     for (int i = 0; i < AgentControllers.Count; i++)
     {
         AgentController cont = AgentControllers[i];
         if (cont.SelectedAgents.Count > 0)
         {
             if (cont.SelectionChanged)
             {
                 com.Select = new Selection(cont.SelectedAgents);
                 cont.SelectionChanged = false;
             }
             else {
                 com.HasSelect = false;
             }
             com.ControllerID = cont.ControllerID;
             com.Select.Serialize (AgentControllers[i].SelectedAgents);
             CommandManager.SendCommand (com);
         }
     }
 }
        protected override void OnExecute(Command com)
        {
            Vector3d forward = com.GetData<Vector3d>();
            Forward = forward;

            this.CalculateRotationValues();
        }
示例#22
0
 public void Execute(Command com)
 {
     leIndex = (byte)com.LeInput;
     ActiveAbility activeAbility = (ActiveAbility)ActiveAbilities [leIndex];
     if (activeAbility != null) {
         activeAbility.Execute (com);
     }
 }
 protected abstract void OnExecute(Command com);
 public static void OrderSpawn(AgentController cont, AgentCode agentCode, int count, Vector2d position)
 {
     Command com = new Command (InputCode.Spawn);
     com.ControllerID = cont.ControllerID;
     com.Position = position;
     com.Target = (ushort)agentCode;
     com.Count = count;
     CommandManager.SendCommand(com);
 }
        public Command GenerateTurnCommand(Vector3 forwards)
        {
            Command com = new Command(this.Data.ListenInputID, this.Agent.Controller.ControllerID);
            Vector3d vecHeight = new Vector3d(forwards);
            com.Add<Vector3d>(vecHeight);
            return com;

        }
        public static void SendCommand(Command com)
        {
            if (sendType == SendState.None) {
                return;
            }
            outCommands.Add (com);

            if (SendAggregated == false) {
                bufferedBytes.FastClear ();
                if (sendType == SendState.Network) {
                    for (int i = 0; i < outCommands.Count; i++) {
                        bufferedBytes.AddRange (outCommands [i].Serialized);
                    }
                    outCommands.FastClear ();
                    if (bufferedBytes.Count > 0)
                        ClientManager.Distribute (bufferedBytes.ToArray ());
                }
            }
        }
 private static void ProcessInterfacer(AbilityInterfacer facer)
 {
     switch (facer.InformationGather)
     {
         case InformationGatherType.Position:
             curCom = new Command(facer.ListenInput);
             curCom.Position = Interfacing.GetWorldPosD(Input.mousePosition);
             break;
         case InformationGatherType.Target:
             curCom = new Command(facer.ListenInput);
             if (Interfacing.MousedAgent .IsNotNull())
             {
                 curCom.Target = Interfacing.MousedAgent.LocalID;
             }
             break;
         case InformationGatherType.PositionOrTarget:
             curCom = new Command(facer.ListenInput);
             if (Interfacing.MousedAgent .IsNotNull())
             {
                 curCom.Target = Interfacing.MousedAgent.GlobalID;
             } else
             {
                 curCom.Position = Interfacing.GetWorldPosD(Input.mousePosition);
             }
             break;
         case InformationGatherType.None:
             curCom = new Command(facer.ListenInput);
             break;
     }
     if (facer.MarkType != MarkerType.None)
     {
         Interfacing.ActivateMarkerOnMouse(facer.MarkType);
     }
     Send(curCom);
 }
		public abstract void Execute (Command com);
 public void Execute(Command com)
 {
     Selection selection = com.Select;
     for (i = 0; i < selection.selectedAgentLocalIDs.Count; i++)
     {
         Agents[selection.selectedAgentLocalIDs[i]].Execute (com);
     }
 }
示例#30
0
 protected override void OnExecute(Command com)
 {
     if (com.HasPosition) {
         Agent.StopCast(ID);
         RegisterGroup ();
      }
 }