Ejemplo n.º 1
0
    public static void SpawnGridWorld(Packet packet)
    {
        WorldGridItem[] worldItems = new WorldGridItem[packet.ReadInt()];
        for (int i = 0; i < worldItems.Length; i++)
        {
            int tileType = packet.ReadInt();

            int cellPositionCount = packet.ReadInt();

            List <Vector3Int> cellPositionList = new List <Vector3Int>();
            for (int k = 0; k < cellPositionCount; k++)
            {
                Vector3Int cell = packet.ReadVector3Int();
                cellPositionList.Add(cell);
            }

            worldItems[i] = new WorldGridItem(tileType, cellPositionList);
        }

        int worldUpdateSequenceNumber = packet.ReadInt();

        WorldUpdate worldUpdate = new WorldUpdate(worldUpdateSequenceNumber, worldItems);

        ClientSideGameManager.instance.SpawnWorldGridElements(worldUpdate);
    }
Ejemplo n.º 2
0
 public void Add(WorldUpdate src)
 {
     if (src is Fork fork)
     {
         foreach (var act in fork.m_Options)
         {
             Add(act);
         }
     }
     else if (src.IsLegal() && !m_Options.Contains(src))
     {
         if (src is Join join)
         {
             var ub = m_Options.Count;
             while (0 <= --ub)
             {
                 if (m_Options[ub] is Join prior_join && prior_join.ForkMerge(join))
                 {
                     return;
                 }
             }
         }
         m_Options.Add(src);
     }
 }
Ejemplo n.º 3
0
 public void HandleWorldUpdate(WorldUpdate wu)
 {
     this.tileZ = wu.tileZ;
     this.updates.Add (wu);
     if (this.updates.Count == wu.totalSequencePackets)
         this.GenerateWorldFromDataStrings (wu.totalSequencePackets);
 }
Ejemplo n.º 4
0
    void UpdateWorld(WorldUpdate newWorldUpdate)
    {
        if (latestWorldUpdate.worldGridItems != null)
        {
            for (int i = 0; i < latestWorldUpdate.worldGridItems.Length; i++)
            {
                for (int j = 0; j < latestWorldUpdate.worldGridItems[i].cellGridWorldPositionList.Count; j++)
                {
                    GridManager.instance.SetTile(latestWorldUpdate.worldGridItems[i].cellGridWorldPositionList[j]
                                                 , (EnumData.TileType)latestWorldUpdate.worldGridItems[i].tileType, false);
                }
            }
        }


        for (int i = 0; i < newWorldUpdate.worldGridItems.Length; i++)
        {
            for (int j = 0; j < newWorldUpdate.worldGridItems[i].cellGridWorldPositionList.Count; j++)
            {
                GridManager.instance.SetTile(newWorldUpdate.worldGridItems[i].cellGridWorldPositionList[j]
                                             , (EnumData.TileType)newWorldUpdate.worldGridItems[i].tileType, true);
            }
        }

        latestWorldUpdate = newWorldUpdate;
    }
Ejemplo n.º 5
0
        public bool ForceRelevant(Location loc, ref WorldUpdate dest)
        {
            var staging = new List <WorldUpdate>();

            foreach (var act in m_Options)
            {
                if (act.IsRelevant(loc))
                {
                    staging.Add(act);
                }
            }
            var staged = staging.Count;

            if (1 > staged)
            {
                throw new InvalidOperationException("tried to force-relevant a not-relevant objective");
            }
            // also of interest: maybe prefilter by whether actions are performable?
            // Fork has a sifting stage here
            if (m_Options.Count > staged)
            {
                dest = new Join(staging, m_Sequel);
            }
            return(false);
        }
Ejemplo n.º 6
0
        public override void OnReceived(IncomingMessage msg)
        {
            switch (msg.ReadInt32())
            {
            case MessageTypes.Spawn:
                SignalManager.Signal(Spawn.Read(msg));
                break;

            case MessageTypes.SynchronizeMessage:

                WorldUpdate update = new WorldUpdate();
                update.Read(msg);

                for (int i = 0; i < 2; i++)
                {
                    SignalManager.Signal(update.Players[i]);
                }

                break;

            case MessageTypes.Move:
                SignalManager.Signal(Movement.Read(msg));
                break;

            case MessageTypes.WorldState:
                break;
            }
        }
Ejemplo n.º 7
0
        public WorldData(WorldUpdate worldUpdate)
        {
            Entities = new List <Entity>();
            Ground   = new List <List <GroundType> >();
            InitGround(40, 40);

            this.Update(worldUpdate);
        }
Ejemplo n.º 8
0
 protected virtual void OnUpdate(WorldUpdate obj)
 {
     var handler = this.Update;
     if (handler != null)
     {
         handler(obj);
     }
 }
Ejemplo n.º 9
0
        public WorldUpdate GetUpdate(string token)
        {
            var worldUpdate = new WorldUpdate();

            //TODO:

            return(worldUpdate);
        }
Ejemplo n.º 10
0
        public Join(List <WorldUpdate> options, WorldUpdate sequel)
        {
            m_Options = options;
            m_Sequel  = sequel;
#if DEBUG
            if (!IsLegal())
            {
                throw new InvalidProgramException("created illegal Join");
            }
#endif
        }
Ejemplo n.º 11
0
        public SharedPlan(WorldUpdate src, Condition <Actor> done)
        {
#if DEBUG
            if (!src.IsLegal())
            {
                throw new InvalidOperationException("illegal objective");
            }
#endif
            m_Plan   = src;
            m_Target = done;
        }
Ejemplo n.º 12
0
        public Fork(WorldUpdate x1, WorldUpdate x2)
        {
            Add(x1);
            Add(x2);
#if DEBUG
            if (!IsLegal())
            {
                throw new InvalidProgramException("created illegal Join");
            }
#endif
        }
Ejemplo n.º 13
0
 private void OnWorldUpdate(WorldUpdate worldUpdate)
 {
     //TODO update WorldData
     if (WorldData == null)
     {
         WorldData = new WorldData(worldUpdate);
     }
     else
     {
         WorldData.Update(worldUpdate);
         this.OnPropertyChanged("WorldData");
     }
 }
Ejemplo n.º 14
0
        public bool ForceRelevant(Location loc, ref WorldUpdate dest)
        {
            var staging = new List <WorldUpdate>();

            foreach (var act in m_Options)
            {
                if (act.IsRelevant(loc))
                {
                    staging.Add(act);
                }
            }
            var staged = staging.Count;

            if (1 > staged)
            {
                throw new InvalidOperationException("tried to force-relevant a not-relevant objective");
            }
            // also of interest: maybe prefilter by whether actions are performable?
            if (2 <= staged)
            {
                var should_sift = staging.HaveItBothWays(act => act is Join);
                if (should_sift.Key)
                {
                    // have Join in here.  non-Join would be faster; would be more useful to retype as Join
                    if (should_sift.Value)
                    {
                        // also have non-Join
#if DEBUG
                        throw new InvalidOperationException("test case");
#endif
                    }
                    else
                    {
                        // random-select a Join
                        dest = Rules.Get.DiceRoller.Choose(staging);
                        return(true);
                    }
                }
            }
            if (2 <= staged)
            {
                if (m_Options.Count > staged)
                {
                    dest = new Fork(staging);
                }
                return(false);
            }
            dest = staging[0];
            return(true);
        }
    public void SendIntoGame(string playerName)
    {
        serverMasterController = ServerSideGameManager.instance.InstantiatePlayer();
        serverMasterController.Initialise(id, playerName, new Vector3(0.5f, 0.5f, 0f));


        //This will send all other players information to our new player
        foreach (ServerSideClient client in Server.clients.Values)
        {
            if (client.serverMasterController != null)
            {
                if (client.id != id)
                {
                    ServerSend.SpawnPlayer(id, client.serverMasterController);
                }
            }
        }


        //This will send new player information to all other players and themselves
        foreach (ServerSideClient client in Server.clients.Values)
        {
            if (client.serverMasterController != null)
            {
                ServerSend.SpawnPlayer(client.id, serverMasterController);
            }
        }



        List <WorldGridItem> worldGridItemList = new List <WorldGridItem>();

        for (int i = 0; i < ServerSideGameManager.instance.toNetworkTileType.Count; i++)
        {
            List <Vector3Int> positionsOfTile = GridManager.instance.GetAllPositionForTileMap(GridManager.instance.gameStateDependentTileArray[(int)ServerSideGameManager.instance.toNetworkTileType[i] - 1].tileMap);
            WorldGridItem     worldGridItem   = new WorldGridItem((int)ServerSideGameManager.instance.toNetworkTileType[i], positionsOfTile);
            worldGridItemList.Add(worldGridItem);
        }
        WorldUpdate worldUpdate = new WorldUpdate(ServerSideGameManager.instance.serverWorldSequenceNumber, worldGridItemList.ToArray());

        ServerSend.SpawnGridWorld(id, worldUpdate);
    }
Ejemplo n.º 16
0
 public void AccumulateWorldUpdatesToBePlayedOnClientFromServer(WorldUpdate worldUpdates)
 {
     if (worldUpdates.sequenceNumber > serverWorldSequenceNumberProcessed)
     {
         WorldUpdate dataPackage;
         if (worldUpdatesFromServerToClientDic.TryGetValue(worldUpdates.sequenceNumber, out dataPackage))
         {
             //Debug.Log("<color=orange>dataPackage already exists for sequence no. </color>" + dataPackage.sequenceNumber);
         }
         else
         {
             //Debug.Log("<color=green>Added successfully to processing buffer dic </color>" + inputCommands.sequenceNumber + "  processed sequence number: " + playerSequenceNumberProcessed);
             worldUpdatesFromServerToClientDic.Add(worldUpdates.sequenceNumber, worldUpdates);
         }
     }
     else
     {
         //Debug.Log("<color=red>Already processed this sequence no </color>" + playerSequenceNumberProcessed);
     }
 }
Ejemplo n.º 17
0
    public static void SpawnGridWorld(int toClient, WorldUpdate worldUpdate)
    {
        using (Packet packet = new Packet((int)ServerPackets.spawnGridWorld))
        {
            packet.Write(worldUpdate.worldGridItems.Length);
            foreach (WorldGridItem worldGridItem in worldUpdate.worldGridItems)
            {
                packet.Write(worldGridItem.tileType);

                packet.Write(worldGridItem.cellGridWorldPositionList.Count);

                foreach (Vector3Int itemCellPosition in worldGridItem.cellGridWorldPositionList)
                {
                    packet.Write(itemCellPosition);
                }
            }
            packet.Write(worldUpdate.sequenceNumber);

            SendTCPData(toClient, packet);
        }
    }
Ejemplo n.º 18
0
 public ActorAction?Bind(Actor who)
 {
     if (m_Plan.IsRelevant(who.Location))
     {
         var test = m_Plan;
         while (ForceRelevant(who.Location, ref test))
         {
             ;
         }
         var act = test.Bind(who);
         if (null != act)
         {
             if (test is Engine.Op.Join join && join.Sequel.IsLegal())
             {
                 m_Plan = join.Sequel;
             }
             else
             {
                 m_Expired = true;
             }
             return(act);
         }
     }
Ejemplo n.º 19
0
        public override void OnConnect(RemoteConnection remote)
        {
            PlayerBase player = new PlayerBase
            {
                Id = (int)remote.ConnectionId,
            };



            Spawn spawn = new Spawn()
            {
                Id = (int)remote.ConnectionId, Position = new Vector2(300, 300), Color = new Color(0.85f, 0.35f, 0.15f)
            };

            players.Add(player);
            SignalManager.Signal(spawn);

            WorldUpdate update = new WorldUpdate();

            update.Players[0] = new Spawn()
            {
                Id = -1, Position = players[0].Position, Color = players[0].Colour
            };
            update.Players[1] = new Spawn()
            {
                Id = players[1].Id, Position = players[1].Position, Color = players[1].Colour
            };

            OutgoingMessage message = MessagePool.CreateMessage();

            update.Write(message);

            remote.Send(message);

            MessagePool.Recycle(message);
        }
Ejemplo n.º 20
0
 public void SpawnWorldGridElements(WorldUpdate worldUpdates)
 {
     UpdateWorld(worldUpdates);
     serverWorldSequenceNumberProcessed = worldUpdates.sequenceNumber;
     Debug.Log("<color=blue>spawned grid world serverWorldSequenceNumberProcessed. </color>" + serverWorldSequenceNumberProcessed);
 }
Ejemplo n.º 21
0
 protected override void Update(GameTime gameTime)
 {
     WorldUpdate.UpdateAllWorld(this, gameTime);
     base.Update(gameTime);
 }
Ejemplo n.º 22
0
 public void Update(WorldUpdate worldUpdate)
 {
     Entities = worldUpdate.LastDelvedEntities;
 }