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); }
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); } }
public void HandleWorldUpdate(WorldUpdate wu) { this.tileZ = wu.tileZ; this.updates.Add (wu); if (this.updates.Count == wu.totalSequencePackets) this.GenerateWorldFromDataStrings (wu.totalSequencePackets); }
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; }
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); }
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; } }
public WorldData(WorldUpdate worldUpdate) { Entities = new List <Entity>(); Ground = new List <List <GroundType> >(); InitGround(40, 40); this.Update(worldUpdate); }
protected virtual void OnUpdate(WorldUpdate obj) { var handler = this.Update; if (handler != null) { handler(obj); } }
public WorldUpdate GetUpdate(string token) { var worldUpdate = new WorldUpdate(); //TODO: return(worldUpdate); }
public Join(List <WorldUpdate> options, WorldUpdate sequel) { m_Options = options; m_Sequel = sequel; #if DEBUG if (!IsLegal()) { throw new InvalidProgramException("created illegal Join"); } #endif }
public SharedPlan(WorldUpdate src, Condition <Actor> done) { #if DEBUG if (!src.IsLegal()) { throw new InvalidOperationException("illegal objective"); } #endif m_Plan = src; m_Target = done; }
public Fork(WorldUpdate x1, WorldUpdate x2) { Add(x1); Add(x2); #if DEBUG if (!IsLegal()) { throw new InvalidProgramException("created illegal Join"); } #endif }
private void OnWorldUpdate(WorldUpdate worldUpdate) { //TODO update WorldData if (WorldData == null) { WorldData = new WorldData(worldUpdate); } else { WorldData.Update(worldUpdate); this.OnPropertyChanged("WorldData"); } }
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); }
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); } }
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); } }
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); } }
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); }
public void SpawnWorldGridElements(WorldUpdate worldUpdates) { UpdateWorld(worldUpdates); serverWorldSequenceNumberProcessed = worldUpdates.sequenceNumber; Debug.Log("<color=blue>spawned grid world serverWorldSequenceNumberProcessed. </color>" + serverWorldSequenceNumberProcessed); }
protected override void Update(GameTime gameTime) { WorldUpdate.UpdateAllWorld(this, gameTime); base.Update(gameTime); }
public void Update(WorldUpdate worldUpdate) { Entities = worldUpdate.LastDelvedEntities; }