public Guid GetInteriorForId() { if (interiorForObj is IHasInterior) { IHasInterior obj = (IHasInterior)interiorForObj; return(obj.GetInteriorForId()); } else { return(Guid.Empty); } }
private void InitializeLoadState(List <ISaveState> LoadFromState) { Dictionary <Guid, Interior> interiorForObjMap = new Dictionary <Guid, Interior>(); // key is the interiorObjFor and val is the interior that belongs to this obj foreach (ISaveState objState in LoadFromState) { // Interiors are deserialized first since they were serialized first if (objState.GetType() == typeof(InteriorState)) { InteriorState its = (InteriorState)objState; Interior i = DeserializeInterior(its); interiorForObjMap.Add(its.interiorForId, i); BoundingBoxLocations.interiorMap.Add(i.interiorId, i); } if (objState.GetType() == typeof(PlayerState)) { PlayerState ps = (PlayerState)objState; player.location = ps.location; player.inventory = DeserializeInventory(ps.inventory); player.inHand = (HandHeld)DeserializeInventoryItem(ps.inHandItemKey); if (ps.playerInInteriorId == Guid.Empty) { player.playerOnShip = null; player.playerInInterior = null; } else { player.entranceLoc = ps.interiorEntranceLocation; // check if the interior already exists foreach (KeyValuePair <Guid, Interior> interior in BoundingBoxLocations.interiorMap) { if (ps.playerInInteriorId == interior.Key) { player.playerInInterior = interior.Value; break; } } } player.onShip = ps.onShip; player.regionKey = ps.region; player.health = ps.health; UpdateOrder.Add(player); } else if (objState.GetType() == typeof(NpcState)) { NpcState npcs = (NpcState)objState; Npc npc = (Npc)DeserializeModel(npcs.objKey, npcs); npc.location = npcs.location; npc.inventory = DeserializeInventory(npcs.inventory); if (npcs.npcInInteriorId == Guid.Empty) { npc.npcInInterior = null; } else { // THIS SHOULD NEVER RUN BECAUSE NPCS THAT ARE IN INTERIORS ARE DESERIALIZED ELSEWHERE // check if the interior already exists foreach (KeyValuePair <Guid, Interior> interior in BoundingBoxLocations.interiorMap) { if (npcs.npcInInteriorId == interior.Key) { npc.npcInInterior = interior.Value; break; } } } npc.onShip = npcs.onShip; npc.regionKey = npcs.region; npc.health = npcs.health; UpdateOrder.Add(npc); } else if (objState.GetType() == typeof(ShipState)) { ShipState ss = (ShipState)objState; Ship s = (Ship)DeserializeModel(ss.objKey, ss); UpdateOrder.Add(s); } else if (objState.GetType() == typeof(StructureState)) { StructureState ss = (StructureState)objState; Structure s = (Structure)DeserializeModel(ss.objKey, ss); UpdateOrder.Add(s); } else if (objState.GetType() == typeof(WeatherSaveState)) { WeatherSaveState wss = (WeatherSaveState)objState; WeatherState.currentLightIntensity = wss.currentLightIntensity; WeatherState.currentMsOfDay = wss.currentMsOfDay; WeatherState.sunAngleX = wss.sunAngleX; WeatherState.shadowTransparency = wss.shadowTransparency; WeatherState.totalDays = wss.nDays; WeatherState.weatherDuration = wss.weatherDuration; WeatherState.msThroughWeather = wss.msThroughWeather; WeatherState.rainState = wss.rainState; WeatherState.rainIntensity = wss.rainIntensity; WeatherState.lightning = wss.lightning; // set the rain for (int i = 0; i < WeatherState.rainIntensity; i++) { WeatherState.rain.Add(new RainDrop(_content, _graphics)); } } else if (objState.GetType() == typeof(OnGroundState)) { OnGroundState ogs = (OnGroundState)objState; Sprite sp = null; if (ogs.inventoryItem) { InventoryItem ii = DeserializeInventoryItem(ogs.objKey); ii.amountStacked = ogs.amountStacked; ii.onGround = true; sp = ii; } else { sp = DeserializeModel(ogs.objKey, objState); } sp.location = ogs.location; sp.regionKey = ogs.region; ItemUtility.ItemsToUpdate.Add(sp); } } // go through newly created world state and set any interiors for the object that owns that interior foreach (Sprite sp in UpdateOrder) { if (sp is IHasInterior) { IHasInterior hasInterior = (IHasInterior)sp; Guid interiorForId = hasInterior.GetInteriorForId(); if (sp is IShip) { Ship sh = (Ship)sp; sh.shipInterior = interiorForObjMap[interiorForId]; } else if (sp is IStructure) { Structure st = (Structure)sp; st.structureInterior = interiorForObjMap[interiorForId]; } interiorForObjMap[interiorForId].interiorForObj = sp; } } // set player's current ship, the interior will be the ships interior if (player.onShip) { player.playerOnShip = (Ship)BoundingBoxLocations.interiorMap[player.playerInInterior.interiorId].interiorForObj; } }