Ejemplo n.º 1
0
 public static bool TryAddLocalCommand(ChangeBehaviourCommand command, World world)
 {
     if (CommandUtils.CommandIsValid(command, world))
     {
         if (volatileChangeBehaviourCommands.ContainsKey(command.Target))
         {
             //el commando es igual al que ya esta almacenado
             if (volatileChangeBehaviourCommands[command.Target].Equals(command))
             {
                 return(false);
             }
             else
             {
                 volatileChangeBehaviourCommands[command.Target] = command;
                 return(true);
             }
         }
         else
         {
             volatileChangeBehaviourCommands.Add(command.Target, command);
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
    public static object[] Serialize(ChangeBehaviourCommand command)
    {
        int entityIndex   = command.Target.Index;
        int entityVersion = command.Target.Version;

        int behaviour = (int)command.NewBehaviour.Value;

        object[] data = new object[] { entityIndex, entityVersion, behaviour };
        return(data);
    }
Ejemplo n.º 3
0
    public static ChangeBehaviourCommand DeserializeChangeBehaviourCommand(object[] data)
    {
        ChangeBehaviourCommand command = new ChangeBehaviourCommand()
        {
            Target = new Entity()
            {
                Index   = (int)data[0],
                Version = (int)data[1]
            },
            NewBehaviour = new GroupBehaviour()
            {
                Value = (Behaviour)data[2]
            }
        };

        return(command);
    }
Ejemplo n.º 4
0
    //event data layout:
    //it must be a object array.
    //and always the first element is the turn of execution.
    private void CommandCallback(EventData photonEvent)
    {
        //null check is important

        object[] eventData     = (object[])photonEvent.CustomData;
        int      turnToExecute = (int)eventData[0];


        object[]      serializedMoveCommands = (object[])eventData[1];
        MoveCommand[] moveCommands;
        if (serializedMoveCommands != null)
        {
            moveCommands = new MoveCommand[serializedMoveCommands.Length];
            for (int i = 0; i < serializedMoveCommands.Length; i++)
            {
                moveCommands[i] = CommandUtils.DeserializeMoveCommand((object[])serializedMoveCommands[i]);
            }
        }
        else
        {
            moveCommands = null;
        }



        object[] serializedChangeBehaviourCommand = (object[])eventData[2];
        ChangeBehaviourCommand[] changeBehaviourCommands;
        if (serializedChangeBehaviourCommand != null)
        {
            changeBehaviourCommands = new ChangeBehaviourCommand[serializedChangeBehaviourCommand.Length];
            for (int i = 0; i < changeBehaviourCommands.Length; i++)
            {
                changeBehaviourCommands[i] = CommandUtils.DeserializeChangeBehaviourCommand((object[])serializedChangeBehaviourCommand[i]);
            }
        }
        else
        {
            changeBehaviourCommands = null;
        }


        object[]        serializedGatherCommand = (object[])eventData[3];
        GatherCommand[] gatherCommands;
        if (serializedGatherCommand != null)
        {
            gatherCommands = new GatherCommand[serializedGatherCommand.Length];
            for (int i = 0; i < gatherCommands.Length; i++)
            {
                gatherCommands[i] = CommandUtils.DeserializeGatherCommand((object[])serializedGatherCommand[i]);
            }
        }
        else
        {
            gatherCommands = null;
        }

        //otros commandos
        CommandStorageSystem.QueueNetworkedCommands(turnToExecute, moveCommands, changeBehaviourCommands, gatherCommands);

        CreateCommandLockstepCheck(turnToExecute);
        SendCommandConfirmationEvent(turnToExecute);
    }
Ejemplo n.º 5
0
 public static bool CommandIsValid(ChangeBehaviourCommand command, World world = null)
 {
     return(TargetIsValid(command.Target, world));
 }
Ejemplo n.º 6
0
 private void ExecuteCommand(ChangeBehaviourCommand command)
 {
     //Debug.Log("setting the destination by command");
     PostUpdateCommands.SetComponent(command.Target, command.NewBehaviour);
     //PostUpdateCommands.AddComponent(command.Target, new RefreshPathNow());
 }