public bool DoStrairsGoUp(SmallMapReferences.SingleMapReference.Location location, int nFloor, Point2D tilePos) { //SmallMapReferences smallMapref = smallMapRef.Get(location, nFloor); SmallMap currentFloorSmallMap = _mapLocationDictionary[location][nFloor]; bool bHasLowerFloor = _mapLocationDictionary[location].ContainsKey(nFloor - 1); bool bHasHigherFllor = _mapLocationDictionary[location].ContainsKey(nFloor + 1); // is it a stair case? Debug.Assert(_spriteTileReferences.IsStaircase(currentFloorSmallMap.TheMap[tilePos.X][tilePos.Y])); // is it the bottom or top floor? if so, then we know if (!bHasLowerFloor) { return(true); } if (!bHasHigherFllor) { return(false); } // is there a stair case on the lower floor? if (_spriteTileReferences.IsStaircase(_mapLocationDictionary[location][nFloor - 1].TheMap[tilePos.X][tilePos.Y])) { return(false); } // is there a stair case on the upper floor? if (_spriteTileReferences.IsStaircase(_mapLocationDictionary[location][nFloor + 1].TheMap[tilePos.X][tilePos.Y])) { return(true); } // if not - then WTF? throw new Ultima5ReduxException("There is staircase with apparently no matching stair case"); }
/// <summary> /// Attempt to enter a building at a coordinate /// Will load new map if successful /// </summary> /// <param name="xy">position of building</param> /// <param name="bWasSuccessful">true if successfully entered</param> /// <returns>output string</returns> public string EnterBuilding(Point2D xy, out bool bWasSuccessful) { bool isOnBuilding = LargeMapRef.IsMapXYEnterable(State.TheVirtualMap.CurrentPosition); string retStr; if (isOnBuilding) { SmallMapReferences.SingleMapReference.Location location = LargeMapRef.GetLocationByMapXY(State.TheVirtualMap.CurrentPosition); //Point2D startingXY = SmallMapReferences.GetStartingXYByLocation(location); State.TheVirtualMap.LoadSmallMap(SmallMapRef.GetSingleMapByLocation(location, 0), State.CharacterRecords, false); // set us to the front of the building State.TheVirtualMap.CurrentPosition = SmallMapReferences.GetStartingXYByLocation(location); retStr = (DataOvlRef.StringReferences.GetString(DataOvlReference.WorldStrings.ENTER_SPACE) + SmallMapRef.GetLocationTypeStr(location)) + "\n" + SmallMapRef.GetLocationName(location); bWasSuccessful = true; } else { retStr = DataOvlRef.StringReferences.GetString(DataOvlReference.WorldStrings.ENTER_SPACE) + DataOvlRef.StringReferences.GetString(DataOvlReference.WorldStrings.WHAT); bWasSuccessful = false; } PassTime(); return(retStr); }
/// <summary> /// Gets a shoppekeeper based on location and NPC type /// </summary> /// <param name="location"></param> /// <param name="npcType"></param> /// <returns></returns> /// <exception cref="ArgumentOutOfRangeException">couldn't find the shoppe keeper at that particular location</exception> public ShoppeKeeper GetShoppeKeeper(SmallMapReferences.SingleMapReference.Location location, NonPlayerCharacterReference.NPCDialogTypeEnum npcType) { switch (npcType) { case NonPlayerCharacterReference.NPCDialogTypeEnum.Blacksmith: return(new BlackSmith(this, _inventory, _shoppeKeeperReferences.GetShoppeKeeperReference(location, npcType), _dataOvlReference)); case NonPlayerCharacterReference.NPCDialogTypeEnum.Barkeeper: break; case NonPlayerCharacterReference.NPCDialogTypeEnum.HorseSeller: break; case NonPlayerCharacterReference.NPCDialogTypeEnum.ShipSeller: break; case NonPlayerCharacterReference.NPCDialogTypeEnum.Healer: break; case NonPlayerCharacterReference.NPCDialogTypeEnum.InnKeeper: break; case NonPlayerCharacterReference.NPCDialogTypeEnum.MagicSeller: break; case NonPlayerCharacterReference.NPCDialogTypeEnum.GuildMaster: break; default: throw new ArgumentOutOfRangeException(nameof(npcType), npcType, null); } return(null); }
/// <summary> /// Gets a replacement sprite for a specific location and position on a map /// </summary> /// <param name="location"></param> /// <param name="position"></param> /// <param name="bOverworld"></param> /// <returns>TileOverride if one exists, otherwise null</returns> public TileOverride GetReplacementSprite(SmallMapReferences.SingleMapReference.Location location, CharacterPosition position, bool bOverworld) { if (!_tileOverrides.ContainsKey((int)location)) { return(null); } if (location == SmallMapReferences.SingleMapReference.Location.Britannia_Underworld) // it's a large map { foreach (TileOverride tileOverride in _tileOverrides[(int)location]) { if (bOverworld && tileOverride.IsOverworld && position == tileOverride.Position) { return(tileOverride); } if (!bOverworld && tileOverride.IsUnderworld && position == tileOverride.Position) { return(tileOverride); } } } else // this is a small map { foreach (TileOverride tileOverride in _tileOverrides[(int)location]) { if (position == tileOverride.Position) { return(tileOverride); } } } return(null); }
/// <summary> /// Climbs the ladder on the current tile that the Avatar occupies /// </summary> public string KlimbLadder() { SmallMapReferences.SingleMapReference.Location location = State.TheVirtualMap.CurrentSingleMapReference.MapLocation; int nCurrentFloor = State.TheVirtualMap.CurrentSingleMapReference.Floor; //currentSingleSmallMapReferences.Floor; bool hasBasement = State.TheVirtualMap.SmallMapRefs.HasBasement(location); int nTotalFloors = State.TheVirtualMap.SmallMapRefs.GetNumberOfFloors(location); int nTopFloor = hasBasement ? nTotalFloors - 1 : nTotalFloors; int ladderDown = SpriteTileReferences.GetTileNumberByName("LadderDown"); int ladderUp = SpriteTileReferences.GetTileNumberByName("LadderUp"); TileReference tileReference = State.TheVirtualMap.GetTileReference(State.TheVirtualMap.CurrentPosition);//GetCurrentTileNumber(); if (tileReference.Index == ladderDown) { if ((hasBasement && nCurrentFloor >= 0) || nCurrentFloor > 0) { State.TheVirtualMap.LoadSmallMap(SmallMapRef.GetSingleMapByLocation(location, nCurrentFloor - 1), false); return(DataOvlRef.StringReferences.GetString(DataOvlReference.TRAVEL_STRINGS.DOWN)); } } else if (tileReference.Index == ladderUp) { if (nCurrentFloor + 1 < nTopFloor) { State.TheVirtualMap.LoadSmallMap(SmallMapRef.GetSingleMapByLocation(location, nCurrentFloor + 1), false); return(DataOvlRef.StringReferences.GetString(DataOvlReference.TRAVEL_STRINGS.UP)); } } return(string.Empty); }
/// <summary> /// Finds all NPCs at a certain location and certain type /// Best used for shoppe keepers /// </summary> /// <param name="location"></param> /// <param name="npcType"></param> /// <returns>NPC Reference</returns> public List <NonPlayerCharacterReference> GetNonPlayerCharacterByLocationAndNPCType( SmallMapReferences.SingleMapReference.Location location, NonPlayerCharacterReference.NPCDialogTypeEnum npcType) { List <NonPlayerCharacterReference> npcRefs = GetNonPlayerCharactersByLocation(location); return(npcRefs.Where(npcRef => npcRef.NPCType == npcType).ToList()); }
public List <NonPlayerCharacterReference> GetNonPlayerCharactersByLocation(SmallMapReferences.SingleMapReference.Location location) { if (!this.locationToNPCsDictionary.ContainsKey(location)) { return(new List <NonPlayerCharacterReference>()); } return(locationToNPCsDictionary[location]); }
/// <summary> /// Create a sign object /// </summary> /// <param name="location">the location the sign is in</param> /// <param name="floor">the floor the sign appears in</param> /// <param name="x">x coord of sign</param> /// <param name="y">y coord of sign</param> /// <param name="signText">Text of sign (may contain unpritable txt that requires fonts from ibm.ch and runes.ch</param> public Sign(SmallMapReferences.SingleMapReference.Location location, int floor, int x, int y, string signText, int nOffset) { Location = location; Floor = floor; X = x; Y = y; RawSignText = signText; Offset = nOffset; //SignText = signText; }
public Sign GetSign(SmallMapReferences.SingleMapReference.Location location, int x, int y) { foreach (Sign sign in _signList) { if (sign.X == x && sign.Y == y && sign.Location == location) { return(sign); } } //throw new Ultima5ReduxException("You asked for a sigh that simple doesn't exist in " + location + " at X=" + x.ToString() + " Y="+y.ToString()); return(null); }
/// <summary> /// Gets a copy of a sign and assigns new X, Y values /// Commonly used for Blackthornes Eight Laws signs /// </summary> /// <param name="location"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="newX">new X value</param> /// <param name="newY">new Y value</param> /// <returns>a new copy of the sign</returns> public Sign CopySign(SmallMapReferences.SingleMapReference.Location location, int x, int y, int newX, int newY) { Sign origSign = GetSign(location, x, y); if (origSign == null) { throw new Ultima5ReduxException("Original sign was not instantiated."); } Sign newSign = new Sign(origSign.Location, origSign.Floor, newX, newY, origSign.RawSignText, origSign.Offset); Debug.Assert(newSign != null); return(newSign); }
public ShoppeKeeperReference GetShoppeKeeperReference(SmallMapReferences.SingleMapReference.Location location, NonPlayerCharacterReference.NPCDialogTypeEnum npcType) { if (!_shoppeKeepersByLocationAndType.ContainsKey(location)) { throw new Ultima5ReduxException("You asked for " + location + " and it wasn't in the _shoppeKeepersByLocationAndType"); } if (!_shoppeKeepersByLocationAndType[location].ContainsKey(npcType)) { throw new Ultima5ReduxException("You asked for " + npcType + " in " + location + " and it wasn't in the _shoppeKeepersByLocationAndType"); } return(_shoppeKeepersByLocationAndType[location][npcType]); }
/// <summary> /// Constructor building xy table /// </summary> /// <param name="dataRef">data ovl reference for extracting xy coordinates</param> public LargeMapLocationReferences(DataOvlReference dataRef) { // Load the location XYs and map them against the location List <byte> xLocs = dataRef.GetDataChunk(DataOvlReference.DataChunkName.LOCATIONS_X).GetAsByteList(); List <byte> yLocs = dataRef.GetDataChunk(DataOvlReference.DataChunkName.LOCATIONS_Y).GetAsByteList(); Debug.Assert(xLocs.Count == yLocs.Count); for (int nVector = 0; nVector < N_TOTAL_LOCATIONS; nVector++) { Point2D mapPoint = new Point2D(xLocs[nVector], yLocs[nVector]); SmallMapReferences.SingleMapReference.Location location = (SmallMapReferences.SingleMapReference.Location)nVector + 1; LocationXY.Add(location, mapPoint); LocationXYLocations.Add(mapPoint, location); } }
public MapCharacter GetMapCharacterByLocation(SmallMapReferences.SingleMapReference.Location location, Point2D xy, int nFloor) { foreach (MapCharacter character in Characters) { // sometimes characters are null because they don't exist - and that is OK if (!character.IsActive) { continue; } if (character.CurrentCharacterPosition.XY == xy && character.CurrentCharacterPosition.Floor == nFloor && character.NPCRef.MapLocation == location) { return(character); } } return(null); }
public LargeMapReference(DataOvlReference dataRef, SmallMapReferences smallMapRef) { // Load the location XYs and map them against the location List <byte> xLocs = dataRef.GetDataChunk(DataOvlReference.DataChunkName.LOCATIONS_X).GetAsByteList(); List <byte> yLocs = dataRef.GetDataChunk(DataOvlReference.DataChunkName.LOCATIONS_Y).GetAsByteList(); Debug.Assert(xLocs.Count == yLocs.Count); // Towns, Dwellings, Castles, Keeps, Dungeons //List<Point2D> vectors = new List<Point2D>(); for (int nVector = 0; nVector < 0x28; nVector++) { Point2D mapPoint = new Point2D(xLocs[nVector], yLocs[nVector]); SmallMapReferences.SingleMapReference.Location location = (SmallMapReferences.SingleMapReference.Location)nVector + 1; //vectors.Add(new Point2D(xLocs[nVector], yLocs[nVector])); // LocationXY.Add((SmallMapReferences.SingleMapReference.Location)nVector + 1, new Point2D(xLocs[nVector], yLocs[nVector])); LocationXY.Add(location, mapPoint); LocationXYLocations.Add(mapPoint, location); } }
/// <summary> /// Construct an NPC /// </summary> /// <param name="mapRef">Which map are they on?</param> /// <param name="sched">daily schedule</param> /// <param name="npcType">type of NPC they are</param> /// <param name="dialogNumber">dialog number referencing data OVL</param> /// <param name="dialogIndex">0-31 index of it's position in the NPC arrays (used for saved.gam references)</param> /// <param name="talkScript">their conversation script</param> public NonPlayerCharacterReference(SmallMapReferences.SingleMapReference.Location location, GameState gameStateRef, NPC_Schedule sched, byte npcType, byte dialogNumber, int dialogIndex, TalkScript talkScript, int nKeySprite) { Schedule = new NonPlayerCharacterSchedule(sched); MapLocation = location; NPCKeySprite = nKeySprite; CharacterType = npcType; DialogNumber = dialogNumber; Script = talkScript; DialogIndex = dialogIndex; this.gameStateRef = gameStateRef; // no schedule? I guess you're not real if (!IsEmptySched(sched)) { System.Console.WriteLine(location.ToString() + " NPC Number: " + this.DialogNumber + " in " + location.ToString()); } }
public string GetLocationName(SmallMapReferences.SingleMapReference.Location location) { Func <DataOvlReference.LOCATION_STRINGS, string> getLocationNameStr = delegate(DataOvlReference.LOCATION_STRINGS index) { return(dataRef.GetStringFromDataChunkList(DataOvlReference.DataChunkName.LOCATION_NAMES, (int)index)); }; // filthy way to convert our more commonly used Location enum to the less used LOCATION_STRINGS // they didn't even bother having them all match, and then decided to leave some out DataOvlReference.LOCATION_STRINGS newLocStrEnum = (DataOvlReference.LOCATION_STRINGS)Enum.Parse(typeof(DataOvlReference.LOCATION_STRINGS), location.ToString()); // if the DataOVL didn't provide a name, then we are forced to set our own... :( if ((int)newLocStrEnum < 0) { switch (newLocStrEnum) { case DataOvlReference.LOCATION_STRINGS.Suteks_Hut: return("SUTEK'S HUT"); case DataOvlReference.LOCATION_STRINGS.SinVraals_Hut: return("SIN VRAAL'S HUT"); case DataOvlReference.LOCATION_STRINGS.Grendels_Hut: return("GRENDAL'S HUT"); case DataOvlReference.LOCATION_STRINGS.Lord_Britishs_Castle: return("LORD BRITISH'S CASTLE"); case DataOvlReference.LOCATION_STRINGS.Palace_of_Blackthorn: return("PALACE OF BLACKTHORN"); default: throw new Exception("Ummm asked for a location name and wasn't on the guest list."); } } else { return(getLocationNameStr(newLocStrEnum)); } }
/// <summary> /// If an NPC is on a tile, then it will get them /// assumes it's on the same floor /// </summary> /// <param name="xy"></param> /// <returns>the NPC or null if one does not exist</returns> public MapCharacter GetNPCOnTile(Point2D xy) { if (IsLargeMap) { return(null); } SmallMapReferences.SingleMapReference.Location location = CurrentSingleMapReference.MapLocation; MapCharacter mapCharacter = TheMapCharacters.GetMapCharacterByLocation(location, xy, CurrentSingleMapReference.Floor); //List<NonPlayerCharacterReference> npcs = nonPlayerCharacters.GetNonPlayerCharactersByLocation(location); //MapCharacterAnimationState characterState = characterStates.GetCharacterStateByPosition(xy, CurrentSingleMapReference.Floor); // get the NPC on the current tile //NonPlayerCharacterReference npc = nonPlayerCharacters.GetNonPlayerCharacter(location, xy, CurrentSingleMapReference.Floor); //if (npc == null) //throw new Exception("You asked for an NPC on a tile that one does not exist - you should have checked first!"); return(mapCharacter); //foreach (NonPlayerCharacters.NonPlayerCharacter npc in npcs) //{ // int nIndex = 1; // Point2D npcXy = npc.Schedule.GetHardCoord(nIndex); // // the NPC is a non-NPC, so we keep looking // if (npcXy.X == 0 && npcXy.Y == 0) continue; // // we found the right NPC and are they on the correct floor // if (npcXy == xy && CurrentSingleMapReference.Floor == npc.Schedule.Coords[nIndex].Z) // { // return npc; // } //} return(null); }
public string GetLocationTypeStr(SmallMapReferences.SingleMapReference.Location location) { // anon function for quick lookup of strings Func <DataOvlReference.WORLD_STRINGS, string> getTypePlaceStr = delegate(DataOvlReference.WORLD_STRINGS index) { return(dataRef.GetStringFromDataChunkList(DataOvlReference.DataChunkName.WORLD, (int)index)); }; switch (location) { case SmallMapReferences.SingleMapReference.Location.Lord_Britishs_Castle: return(getTypePlaceStr(DataOvlReference.WORLD_STRINGS.to_enter_CASTLE_LB)); case SmallMapReferences.SingleMapReference.Location.Palace_of_Blackthorn: return(getTypePlaceStr(DataOvlReference.WORLD_STRINGS.to_enter_PALACE_B)); case SmallMapReferences.SingleMapReference.Location.East_Britanny: case SmallMapReferences.SingleMapReference.Location.West_Britanny: case SmallMapReferences.SingleMapReference.Location.North_Britanny: case SmallMapReferences.SingleMapReference.Location.Paws: case SmallMapReferences.SingleMapReference.Location.Cove: return(getTypePlaceStr(DataOvlReference.WORLD_STRINGS.to_enter_VILLAGE)); case SmallMapReferences.SingleMapReference.Location.Buccaneers_Den: return(getTypePlaceStr(DataOvlReference.WORLD_STRINGS.to_enter_KEEP)); case SmallMapReferences.SingleMapReference.Location.Moonglow: case SmallMapReferences.SingleMapReference.Location.Britain: case SmallMapReferences.SingleMapReference.Location.Jhelom: case SmallMapReferences.SingleMapReference.Location.Yew: case SmallMapReferences.SingleMapReference.Location.Minoc: case SmallMapReferences.SingleMapReference.Location.Trinsic: case SmallMapReferences.SingleMapReference.Location.Skara_Brae: case SmallMapReferences.SingleMapReference.Location.New_Magincia: return(getTypePlaceStr(DataOvlReference.WORLD_STRINGS.to_enter_TOWNE)); case SmallMapReferences.SingleMapReference.Location.Fogsbane: case SmallMapReferences.SingleMapReference.Location.Stormcrow: case SmallMapReferences.SingleMapReference.Location.Waveguide: case SmallMapReferences.SingleMapReference.Location.Greyhaven: return(getTypePlaceStr(DataOvlReference.WORLD_STRINGS.to_enter_LIGHTHOUSE)); case SmallMapReferences.SingleMapReference.Location.Iolos_Hut: //case Location.spektran case SmallMapReferences.SingleMapReference.Location.Suteks_Hut: case SmallMapReferences.SingleMapReference.Location.SinVraals_Hut: case SmallMapReferences.SingleMapReference.Location.Grendels_Hut: return(getTypePlaceStr(DataOvlReference.WORLD_STRINGS.to_enter_HUT)); case SmallMapReferences.SingleMapReference.Location.Ararat: return(getTypePlaceStr(DataOvlReference.WORLD_STRINGS.to_enter_RUINS)); case SmallMapReferences.SingleMapReference.Location.Bordermarch: case SmallMapReferences.SingleMapReference.Location.Farthing: case SmallMapReferences.SingleMapReference.Location.Windemere: case SmallMapReferences.SingleMapReference.Location.Stonegate: case SmallMapReferences.SingleMapReference.Location.Lycaeum: case SmallMapReferences.SingleMapReference.Location.Empath_Abbey: case SmallMapReferences.SingleMapReference.Location.Serpents_Hold: return(getTypePlaceStr(DataOvlReference.WORLD_STRINGS.to_enter_KEEP)); case SmallMapReferences.SingleMapReference.Location.Deceit: case SmallMapReferences.SingleMapReference.Location.Despise: case SmallMapReferences.SingleMapReference.Location.Destard: case SmallMapReferences.SingleMapReference.Location.Wrong: case SmallMapReferences.SingleMapReference.Location.Covetous: case SmallMapReferences.SingleMapReference.Location.Shame: case SmallMapReferences.SingleMapReference.Location.Hythloth: case SmallMapReferences.SingleMapReference.Location.Doom: return(getTypePlaceStr(DataOvlReference.WORLD_STRINGS.to_enter_DUNGEON)); } return(""); }
public Sign(SmallMapReferences.SingleMapReference.Location location, int floor, int x, int y, byte[] signText, int nOffset) : this(location, floor, x, y, ScrubSignText(signText), nOffset) { }
/// <summary> /// Gets a copy of a sign and assigns new X, Y values /// Commonly used for Blackthornes Eight Laws signs /// </summary> /// <param name="location"></param> /// <param name="x"></param> /// <param name="y"></param> /// <param name="newX">new X value</param> /// <param name="newY">new Y value</param> /// <returns>a new copy of the sign</returns> public Sign CopySign(SmallMapReferences.SingleMapReference.Location location, int x, int y, int newX, int newY) { Sign origSign = GetSign(location, x, y); return(new Sign(origSign.Location, origSign.Floor, newX, newY, origSign.RawSignText, origSign.Offset)); }
public bool DoStairsGoDown(SmallMapReferences.SingleMapReference.Location location, int nFloor, Point2D tilePos) { return(!DoStrairsGoUp(location, nFloor, tilePos)); }
public SmallMap GetSmallMap(SmallMapReferences.SingleMapReference.Location location, int nFloor) { return(_mapLocationDictionary[location][nFloor]); }
// left over structure /* [StructLayout(LayoutKind.Sequential, Pack = 1)] * private unsafe struct NPC_Info * { * NPC_Schedule schedule[32]; * fixed byte type[32]; // merchant, guard, etc. * fixed byte dialog_number[32]; * };*/ #endregion #region Initialization and Constructor routines /// <summary> /// Initialize NPCs from a particular small map master file set /// </summary> /// <param name="u5Directory">Directory with Ultima 5</param> /// <param name="mapMaster">The master map from which to load</param> /// <param name="smallMapRef">Small map reference to help link NPCs to a map</param> private void InitializeNPCs(string u5Directory, SmallMapReferences.SingleMapReference.SmallMapMasterFiles mapMaster, SmallMapReferences smallMapRef, TalkScripts talkScriptsRef, GameState gameStateRef) { // open the appropriate NPC data file string dataFilenameAndPath = Path.Combine(u5Directory, SmallMapReferences.SingleMapReference.GetNPCFilenameFromMasterFile(mapMaster)); // load the file into memory List <byte> npcData = Utils.GetFileAsByteList(dataFilenameAndPath); for (int nTown = 0; nTown < TOWNS_PER_NPCFILE; nTown++) { // fresh collections for each major loop to guarantee they are clean List <NonPlayerCharacterReference.NPC_Schedule> schedules = new List <NonPlayerCharacterReference.NPC_Schedule>(NPCS_PER_TOWN); List <byte> npcTypes = new List <byte>(NPCS_PER_TOWN); List <byte> npcDialogNumber = new List <byte>(NPCS_PER_TOWN); SmallMapReferences.SingleMapReference.Location location = smallMapRef.GetLocationByIndex(mapMaster, nTown); SmallMapReferences.SingleMapReference singleMapRef = smallMapRef.GetSingleMapByLocation(location, 0); //sing = SmallMapRef.GetSingleMapByLocation(SmallMapRef.GetLocationByIndex(mapMaster, nTown); int townOffset = (TOWN_OFFSET_SIZE * nTown); // bajh: I know this could be done in a single loop, but it would be so damn ugly that I honestly don't even want to both // read through the schedules first int count = 0; // start at the town offset, incremenet by an NPC record each time, for 32 loops for (int offset = townOffset; count < NPCS_PER_TOWN; offset += SCHEDULE_OFFSET_SIZE, count++) { NonPlayerCharacterReference.NPC_Schedule sched = (NonPlayerCharacterReference.NPC_Schedule)Utils.ReadStruct(npcData, offset, typeof(NonPlayerCharacterReference.NPC_Schedule)); schedules.Add(sched); } // bajh: just shoot me if I ever have to write this again - why on earth did LB write all of his data in different formats! // these are single byte, so we can capture them just by jumping to their offsets count = 0; for (int offset = townOffset; count < NPCS_PER_TOWN; offset++, count++) { // add NPC type npcTypes.Add(npcData[offset + STARTING_NPC_TYPE_TOWN_OFFSET]); // add NPC dialog # npcDialogNumber.Add(npcData[offset + STARTING_NPC_DIALOG_TOWN_OFFSET]); } List <byte> keySpriteList = gameStateRef.NonPlayerCharacterKeySprites.GetAsByteList(); // go over all of the NPCs, create them and add them to the collection for (int nNpc = 0; nNpc < NPCS_PER_TOWN; nNpc++) { NonPlayerCharacterReference npc = new NonPlayerCharacterReference(location, gameStateRef, schedules[nNpc], npcTypes[nNpc], npcDialogNumber[nNpc], nNpc, talkScriptsRef.GetTalkScript(mapMaster, npcDialogNumber[nNpc]), (int)(keySpriteList[nNpc] + 100)); npcs.Add(npc); // we also create a quick lookup table by location but first need to check that there is an initialized list inside if (!locationToNPCsDictionary.ContainsKey(singleMapRef.MapLocation)) { locationToNPCsDictionary.Add(singleMapRef.MapLocation, new List <NonPlayerCharacterReference>()); } locationToNPCsDictionary[singleMapRef.MapLocation].Add(npc); } } }
/// <summary> /// Climbs the ladder on the current tile that the Avatar occupies /// </summary> public string TryToKlimb(out KlimbResult klimbResult) { string getKlimbOutput(string output = "") { if (output == "") { return(DataOvlRef.StringReferences.GetString(DataOvlReference.TravelStrings.KLIMB)); } return(DataOvlRef.StringReferences.GetString(DataOvlReference.TravelStrings.KLIMB) + output); } TileReference curTileRef = State.TheVirtualMap.GetTileReferenceOnCurrentTile(); // if it's a large map, we either klimb with the grapple or don't klimb at all if (State.TheVirtualMap.IsLargeMap) { if (State.HasGrapple) // we don't have a grapple, so we can't klimb { klimbResult = KlimbResult.RequiresDirection; return(getKlimbOutput()); } klimbResult = KlimbResult.CantKlimb; return(getKlimbOutput(DataOvlRef.StringReferences.GetString(DataOvlReference.KlimbingStrings.WITH_WHAT))); } // we can't klimb on the current tile, so we need to pick a direction if (!SpriteTileReferences.IsLadder(curTileRef.Index) && !SpriteTileReferences.IsGrate(curTileRef.Index)) { klimbResult = KlimbResult.RequiresDirection; return(getKlimbOutput()); } SmallMapReferences.SingleMapReference.Location location = State.TheVirtualMap.CurrentSingleMapReference.MapLocation; int nCurrentFloor = State.TheVirtualMap.CurrentSingleMapReference.Floor; bool hasBasement = State.TheVirtualMap.SmallMapRefs.HasBasement(location); int nTotalFloors = State.TheVirtualMap.SmallMapRefs.GetNumberOfFloors(location); int nTopFloor = hasBasement ? nTotalFloors - 1 : nTotalFloors; TileReference tileReference = State.TheVirtualMap.GetTileReference(State.TheVirtualMap.CurrentPosition); if (SpriteTileReferences.IsLadderDown(tileReference.Index) || SpriteTileReferences.IsGrate(tileReference.Index)) { if ((hasBasement && nCurrentFloor >= 0) || nCurrentFloor > 0) { State.TheVirtualMap.LoadSmallMap(SmallMapRef.GetSingleMapByLocation(location, nCurrentFloor - 1), State.CharacterRecords, false); klimbResult = KlimbResult.Success; return(getKlimbOutput(DataOvlRef.StringReferences.GetString(DataOvlReference.TravelStrings.DOWN))); } } else if (SpriteTileReferences.IsLadderUp(tileReference.Index)) { if (nCurrentFloor + 1 < nTopFloor) { State.TheVirtualMap.LoadSmallMap(SmallMapRef.GetSingleMapByLocation(location, nCurrentFloor + 1), State.CharacterRecords, false); klimbResult = KlimbResult.Success; return(getKlimbOutput(DataOvlRef.StringReferences.GetString(DataOvlReference.TravelStrings.UP))); } } klimbResult = KlimbResult.RequiresDirection; return(getKlimbOutput()); }
static public Point2D GetStartingXYByLocation(SmallMapReferences.SingleMapReference.Location location) { return(new Point2D(32 / 2 - 1, 30)); }