/// <summary> /// The only time this should be used is to populate EquippedObjects from the ctor. /// </summary> protected void AddBiotasToEquippedObjects(IEnumerable <Biota> wieldedItems) { foreach (var biota in wieldedItems) { var worldObject = WorldObjectFactory.CreateWorldObject(biota); EquippedObjects[worldObject.Guid] = worldObject; EncumbranceVal += worldObject.EncumbranceVal; } EquippedObjectsLoaded = true; }
/// <summary> /// Launches a projectile from player to target /// </summary> public WorldObject LaunchProjectile(WorldObject ammo, WorldObject target, out float time) { var proj = WorldObjectFactory.CreateNewWorldObject(ammo.WeenieClassId); proj.ProjectileSource = this; proj.ProjectileTarget = target; var matchIndoors = Location.Indoors == target.Location.Indoors; var origin = matchIndoors ? Location.ToGlobal() : Location.Pos; origin.Z += Height; var dest = matchIndoors ? target.Location.ToGlobal() : target.Location.Pos; dest.Z += target.Height / GetAimHeight(target); var speed = 35.0f; // TODO: get correct speed var dir = GetDir2D(origin, dest); origin += dir * 2.0f; var velocity = GetProjectileVelocity(target, origin, dir, dest, speed, out time); proj.Velocity = new AceVector3(velocity.X, velocity.Y, velocity.Z); proj.Location = matchIndoors ? Location.FromGlobal(origin) : new Position(Location.Cell, origin, Location.Rotation); if (!matchIndoors) { proj.Location.LandblockId = new LandblockId(proj.Location.GetCell()); } SetProjectilePhysicsState(proj, target); LandblockManager.AddObject(proj); var player = this as Player; var pkStatus = player?.PlayerKillerStatus ?? PlayerKillerStatus.Creature; proj.EnqueueBroadcast(new GameMessagePublicUpdatePropertyInt(proj, PropertyInt.PlayerKillerStatus, (int)pkStatus)); proj.EnqueueBroadcast(new GameMessageScript(proj.Guid, ACE.Entity.Enum.PlayScript.Launch, 0f)); // detonate point-blank projectiles immediately var radsum = target.PhysicsObj.GetRadius() + proj.PhysicsObj.GetRadius(); var dist = Vector3.Distance(origin, dest); if (dist < radsum) { proj.OnCollideObject(target); } return(proj); }
/// <summary> /// Corpses<para /> /// This will be called from a separate task from our constructor. Use thread safety when interacting with this landblock. /// </summary> private void SpawnDynamicShardObjects() { var dynamics = DatabaseManager.Shard.GetDynamicObjectsByLandblock(Id.Landblock); var factoryShardObjects = WorldObjectFactory.CreateWorldObjects(dynamics); actionQueue.EnqueueAction(new ActionEventDelegate(() => { foreach (var fso in factoryShardObjects) { AddWorldObject(fso); } })); }
/// <summary> /// Gives default ranged ammo if none in wielded treasure /// </summary> public void GiveAmmo() { var ammo = GetEquippedAmmo(); if (ammo != null) { return; } ammo = WorldObjectFactory.CreateNewWorldObject(300); TryEquipObject(ammo, (int)EquipMask.MissileAmmo); SetChild(ammo, (int)ammo.CurrentWieldedLocation, out var placementId, out var parentLocation); }
public void AddWeeniePiece(BasePiece piece) { var frame = new AFrame(ChessBoard.PhysicsObj.Position.Frame); CalculateWeeniePosition(piece.Coord, piece.Color, frame); var monster = piece.Color == ChessColor.Black ? "drudge" : "mosswart"; var weeniename = ""; switch (piece.Type) { case ChessPieceType.Pawn: weeniename = $"{monster}pawn"; break; case ChessPieceType.Rook: weeniename = $"{monster}rook"; break; case ChessPieceType.Knight: weeniename = $"{monster}knight"; break; case ChessPieceType.Bishop: weeniename = $"{monster}bishop"; break; case ChessPieceType.Queen: weeniename = $"{monster}queen"; break; case ChessPieceType.King: weeniename = $"{monster}king"; break; } var wo = WorldObjectFactory.CreateNewWorldObject(weeniename); //Console.WriteLine($"AddWeeniePiece: {weeniename}, {piece.Coord}, {frame.Origin}"); // add to position, spawn wo.Location = new Position(ChessBoard.Location); wo.Location.Pos = frame.Origin; wo.Location.Rotation = frame.Orientation; wo.EnterWorld(); piece.Guid = wo.Guid; (wo as GamePiece).ChessMatch = this; }
private static void AddWeeniesToInventory(Session session, HashSet <uint> weenieIds) { foreach (uint weenieId in weenieIds) { var loot = WorldObjectFactory.CreateNewWorldObject(weenieId); if (loot == null) // weenie doesn't exist { continue; } session.Player.TryCreateInInventoryWithNetworking(loot); } }
public Landblock(LandblockId id) { this.id = id; UpdateStatus(LandBlockStatusFlag.IdleUnloaded); // initialize adjacency array adjacencies.Add(Adjacency.North, null); adjacencies.Add(Adjacency.NorthEast, null); adjacencies.Add(Adjacency.East, null); adjacencies.Add(Adjacency.SouthEast, null); adjacencies.Add(Adjacency.South, null); adjacencies.Add(Adjacency.SouthWest, null); adjacencies.Add(Adjacency.West, null); adjacencies.Add(Adjacency.NorthWest, null); UpdateStatus(LandBlockStatusFlag.IdleLoading); actionQueue = new NestedActionQueue(WorldManager.ActionQueue); // TODO: Load cell.dat contents // 1. landblock cell structure // 2. terrain data // TODO: Load portal.dat contents (as/if needed) // TODO: Load spawn data var objects = DatabaseManager.World.GetWeenieInstancesByLandblock(this.id.Landblock); // Instances // FIXME: Likely the next line should be eliminated after generators have been refactored into the instance structure, if that ends up making the most sense // I don't know for sure however that it does yet. More research on them is required -Ripley objects.AddRange(DatabaseManager.World.GetObjectsByLandblock(this.id.Landblock)); // Generators var factoryObjects = WorldObjectFactory.CreateWorldObjects(objects); factoryObjects.ForEach(fo => { if (!worldObjects.ContainsKey(fo.Guid)) { worldObjects.Add(fo.Guid, fo); fo.SetParent(this); } }); UpdateStatus(LandBlockStatusFlag.IdleLoaded); // FIXME(ddevec): Goal: get rid of UseTime() function... actionQueue.EnqueueAction(new ActionEventDelegate(() => UseTimeWrapper())); motionQueue = new NestedActionQueue(WorldManager.MotionQueue); }
/// <summary> /// The only time this should be used is to populate EquippedObjects from the ctor. /// </summary> protected void AddBiotasToEquippedObjects(IEnumerable <ACE.Database.Models.Shard.Biota> wieldedItems) { foreach (var biota in wieldedItems) { var worldObject = WorldObjectFactory.CreateWorldObject(biota); EquippedObjects[worldObject.Guid] = worldObject; EncumbranceVal += (worldObject.EncumbranceVal ?? 0); } EquippedObjectsLoaded = true; SetChildren(); }
/// <summary> /// Spawns the semi-randomized monsters scattered around the outdoors<para /> /// This will be called from a separate task from our constructor. Use thread safety when interacting with this landblock. /// </summary> private void SpawnEncounters() { // get the encounter spawns for this landblock var encounters = DatabaseManager.World.GetCachedEncountersByLandblock(Id.Landblock); foreach (var encounter in encounters) { var wo = WorldObjectFactory.CreateNewWorldObject(encounter.WeenieClassId); if (wo == null) { continue; } var xPos = Math.Clamp(encounter.CellX * 24.0f, 0.5f, 191.5f); var yPos = Math.Clamp(encounter.CellY * 24.0f, 0.5f, 191.5f); var pos = new Physics.Common.Position(); pos.ObjCellID = (uint)(Id.Landblock << 16) | 1; pos.Frame = new Physics.Animation.AFrame(new Vector3(xPos, yPos, 0), Quaternion.Identity); pos.adjust_to_outside(); pos.Frame.Origin.Z = _landblock.GetZ(pos.Frame.Origin); wo.Location = new Position(pos.ObjCellID, pos.Frame.Origin, pos.Frame.Orientation); var sortCell = LScape.get_landcell(pos.ObjCellID) as SortCell; if (sortCell != null && sortCell.has_building()) { continue; } if (PropertyManager.GetBool("override_encounter_spawn_rates").Item) { wo.RegenerationInterval = PropertyManager.GetDouble("encounter_regen_interval").Item; wo.ReinitializeHeartbeats(); foreach (var profile in wo.Biota.BiotaPropertiesGenerator) { profile.Delay = (float)PropertyManager.GetDouble("encounter_delay").Item; } } actionQueue.EnqueueAction(new ActionEventDelegate(() => { AddWorldObject(wo); })); } }
public Landblock(LandblockId id) { Id = id; //Console.WriteLine("Landblock constructor(" + (id.Raw | 0xFFFF).ToString("X8") + ")"); UpdateStatus(LandBlockStatusFlag.IdleUnloaded); // initialize adjacency array adjacencies.Add(Adjacency.North, null); adjacencies.Add(Adjacency.NorthEast, null); adjacencies.Add(Adjacency.East, null); adjacencies.Add(Adjacency.SouthEast, null); adjacencies.Add(Adjacency.South, null); adjacencies.Add(Adjacency.SouthWest, null); adjacencies.Add(Adjacency.West, null); adjacencies.Add(Adjacency.NorthWest, null); UpdateStatus(LandBlockStatusFlag.IdleLoading); // create world objects (monster locations, generators) var objects = DatabaseManager.World.GetCachedInstancesByLandblock(Id.Landblock); var factoryObjects = WorldObjectFactory.CreateNewWorldObjects(objects); foreach (var fo in factoryObjects) { AddWorldObject(fo); fo.ActivateLinks(); } // create shard objects (corpses after unloading) DatabaseManager.Shard.GetObjectsByLandblock(Id.Landblock, ((List <Biota> biotas) => { var shardObjects = (WorldObjectFactory.CreateWorldObjects(biotas)); foreach (var so in shardObjects) { AddWorldObject(so); } })); _landblock = LScape.get_landblock(Id.Raw); //LoadMeshes(objects); SpawnEncounters(); UpdateStatus(LandBlockStatusFlag.IdleLoaded); lastActiveTime = DateTime.UtcNow; }
private WorldObjectBitNumberFactoryPicker CreateCornerFactory(IBlueprintBuilder builder) { var baseCornerFactories = new IFactory <IWorldObject> [8]; baseCornerFactories[0] = new WorldObjectFactory(roundCornerFactory); baseCornerFactories[1] = new WorldObjectFactory(straightUpCornerFactory); baseCornerFactories[2] = new WorldObjectFactory(straightRightCornerFactory); baseCornerFactories[3] = new WorldObjectFactory(diagonalMissingCornerFactory); baseCornerFactories[4] = new WorldObjectFactory(roundCornerFactory); baseCornerFactories[5] = new WorldObjectFactory(outsideUpCornerFactory); baseCornerFactories[6] = new WorldObjectFactory(outsideRightCornerFactory); baseCornerFactories[7] = new WorldObjectFactory(closedCornerFactory); return(new WorldObjectBitNumberFactoryPicker(baseCornerFactories, new CornerBlocksNumberGenerator(builder))); }
/// <summary> /// Monster Locations, Generators<para /> /// This will be called from a separate task from our constructor. Use thread safety when interacting with this landblock. /// </summary> private void CreateWorldObjects() { var objects = DatabaseManager.World.GetCachedInstancesByLandblock(Id.Landblock); var shardObjects = DatabaseManager.Shard.GetStaticObjectsByLandblock(Id.Landblock); var factoryObjects = WorldObjectFactory.CreateNewWorldObjects(objects, shardObjects); actionQueue.EnqueueAction(new ActionEventDelegate(() => { foreach (var fo in factoryObjects) { AddWorldObject(fo); fo.ActivateLinks(objects, shardObjects); } })); }
public static void InstantiateObject(int x, int z, int y, Tile.ID id, WorldObjectContainer worldObjects) { GameObject obj = WorldObjectFactory.Instantiate(x, z, y, id); if (obj == null) { return; } ObjectData objData = obj.AddComponent <ObjectData>(); objData.Init(worldObjects, id, x, z, y); worldObjects.SetObject(x, z, y, obj); obj.transform.SetParent(worldObjects.GetParent()); }
public static void MoveTo(Session session, params string[] parameters) { var distance = 10.0f; ushort trainingWandTarget = 12748; if ((parameters?.Length > 0)) { distance = Convert.ToInt16(parameters[0]); } WorldObject loot = WorldObjectFactory.CreateNewWorldObject(trainingWandTarget); LootGenerationFactory.Spawn(loot, session.Player.Location.InFrontOf(distance)); session.Player.PutItemInContainer(loot.Guid, session.Player.Guid); }
/// <summary> /// Returns the full allegiance structure for any player /// </summary> /// <param name="player">A player at any level of an allegiance</param> public static Allegiance GetAllegiance(IPlayer player) { if (player == null) { return(null); } var monarch = GetMonarch(player); if (monarch == null) { return(null); } // is this allegiance already loaded / cached? if (Players.ContainsKey(monarch.Guid)) { return(Players[monarch.Guid].Allegiance); } // try to load biota var allegianceID = DatabaseManager.Shard.GetAllegianceID(monarch.Guid.Full); var biota = allegianceID != null?DatabaseManager.Shard.GetBiota(allegianceID.Value) : null; var allegiance = biota != null ? new Allegiance(biota) : new Allegiance(monarch.Guid); if (allegiance.TotalMembers == 1) { return(null); } if (biota == null) { allegiance = WorldObjectFactory.CreateNewWorldObject("allegiance") as Allegiance; allegiance.MonarchId = monarch.Guid.Full; allegiance.Init(monarch.Guid); allegiance.SaveBiotaToDatabase(); } AddPlayers(allegiance); //if (!Allegiances.ContainsKey(allegiance.Guid)) //Allegiances.Add(allegiance.Guid, allegiance); Allegiances[allegiance.Guid] = allegiance; return(allegiance); }
public GameEventApproachVendor(Session session, WorldObject vendor, List <WorldObject> items) : base(GameEventType.ApproachVendor, GameMessageGroup.Group09, session) { Writer.Write(vendor.Guid.Full); // merchant id // bit mask ? categories / mask may need figured out more. Writer.Write((uint)vendor.MerchandiseItemTypes); Writer.Write((uint)vendor.MerchandiseMinValue); Writer.Write((uint)vendor.MerchandiseMaxValue); Writer.Write((uint)(vendor.DealMagicalItems ?? false ? 1 : 0)); // magic Writer.Write((float)vendor.BuyPrice); // buy_price Writer.Write((float)vendor.SellPrice); // sell_price Writer.Write(vendor.AlternateCurrencyDID ?? 0u); // trade id .. wcid of currency vendor uses if (vendor.AlternateCurrencyDID > 0) { var currency = WorldObjectFactory.CreateWorldObject(Database.DatabaseManager.World.GetAceObjectByWeenie((uint)vendor.AlternateCurrencyDID)); string fixedPlural = currency.NamePlural; if (fixedPlural == null) { fixedPlural = currency.Name; if (fixedPlural.EndsWith("ch") || fixedPlural.EndsWith("s") || fixedPlural.EndsWith("sh") || fixedPlural.EndsWith("x") || fixedPlural.EndsWith("z")) { fixedPlural += "es"; } else { fixedPlural += "s"; } } Writer.Write((uint)0); // trade number .. current amount of that currency player has on hand, need a function to return # of items of specific wcid found in inventory Writer.WriteString16L(fixedPlural); // the name of that currency } else { Writer.Write((uint)0); // trade number .. current amount of that currency player has on hand, need a function to return # of items of specific wcid found in inventory Writer.WriteString16L(""); // the name of that currency } Writer.Write((uint)items.Count); // number of items foreach (WorldObject obj in items) { // Serialize Stream. Writer.Write(0xFFFFFFFF); // pretty sure this is either -1 (0xFFFFFFFF) or specific amount of item.. limited quanity obj.SerializeGameDataOnly(Writer); } Writer.Align(); }
/// <summary> /// The only time this should be used is to populate Inventory from the ctor. /// </summary> protected void SortBiotasIntoInventory(IEnumerable <ACE.Database.Models.Shard.Biota> biotas) { var worldObjects = new List <WorldObject>(); foreach (var biota in biotas) { worldObjects.Add(WorldObjectFactory.CreateWorldObject(biota)); } SortWorldObjectsIntoInventory(worldObjects); if (worldObjects.Count > 0) { Console.WriteLine("Inventory detected without a container to put it in to."); } }
private List <WorldObject> CreatePayoutCoinStacks(int amount) { var coinStacks = new List <WorldObject>(); while (amount > 0) { var currencyStack = WorldObjectFactory.CreateNewWorldObject("coinstack"); var currentStackAmount = Math.Min(amount, currencyStack.MaxStackSize.Value); currencyStack.SetStackSize(currentStackAmount); coinStacks.Add(currencyStack); amount -= currentStackAmount; } return(coinStacks); }
/// <summary> /// The only time this should be used is to populate Inventory from the ctor. /// </summary> protected void SortBiotasIntoInventory(IEnumerable <Biota> biotas) { var worldObjects = new List <WorldObject>(); foreach (var biota in biotas) { worldObjects.Add(WorldObjectFactory.CreateWorldObject(biota)); } SortWorldObjectsIntoInventory(worldObjects); if (worldObjects.Count > 0) { log.Error("Inventory detected without a container to put it in to."); } }
// ========================= // Helper Functions - Buying // ========================= /// <summary> /// Used to convert Weenie based objects / not used for unique items /// </summary> private List <WorldObject> ItemProfileToWorldObjects(ItemProfile itemprofile) { List <WorldObject> worldobjects = new List <WorldObject>(); while (itemprofile.Amount > 0) { WorldObject wo = WorldObjectFactory.CreateNewWorldObject(itemprofile.WeenieClassId); if (itemprofile.Palette.HasValue) { wo.PaletteTemplate = itemprofile.Palette; } if (itemprofile.Shade.HasValue) { wo.Shade = itemprofile.Shade; } // can we stack this ? if (wo.MaxStackSize.HasValue) { if ((wo.MaxStackSize.Value != 0) & (wo.MaxStackSize.Value <= itemprofile.Amount)) { wo.SetStackSize(wo.MaxStackSize.Value); worldobjects.Add(wo); itemprofile.Amount = itemprofile.Amount - wo.MaxStackSize.Value; } else // we cant stack this but its not a single item { wo.SetStackSize((int)itemprofile.Amount); worldobjects.Add(wo); itemprofile.Amount = itemprofile.Amount - itemprofile.Amount; } } else { // if there multiple items of the same type.. if (itemprofile.Amount > 0) { // single item with no stack options. itemprofile.Amount = itemprofile.Amount - 1; wo.StackSize = null; worldobjects.Add(wo); } } } return(worldobjects); }
public static WorldObject SpawnEncounter(Weenie weenie, int cellX, int cellY, Position pos, Session session) { var wo = WorldObjectFactory.CreateNewWorldObject(weenie.ClassId); if (wo == null) { Console.WriteLine($"Failed to create encounter weenie"); return(null); } var xPos = Math.Clamp(cellX * 24.0f, 0.5f, 191.5f); var yPos = Math.Clamp(cellY * 24.0f, 0.5f, 191.5f); var newPos = new Physics.Common.Position(); newPos.ObjCellID = pos.Cell; newPos.Frame = new Physics.Animation.AFrame(new Vector3(xPos, yPos, 0), Quaternion.Identity); newPos.adjust_to_outside(); newPos.Frame.Origin.Z = session.Player.CurrentLandblock.PhysicsLandblock.GetZ(newPos.Frame.Origin); wo.Location = new Position(newPos.ObjCellID, newPos.Frame.Origin, newPos.Frame.Orientation); var sortCell = Physics.Common.LScape.get_landcell(newPos.ObjCellID) as Physics.Common.SortCell; if (sortCell != null && sortCell.has_building()) { Console.WriteLine($"Failed to create encounter near building cell"); return(null); } if (PropertyManager.GetBool("override_encounter_spawn_rates").Item) { wo.RegenerationInterval = PropertyManager.GetDouble("encounter_regen_interval").Item; wo.ReinitializeHeartbeats(); foreach (var profile in wo.Biota.BiotaPropertiesGenerator) { profile.Delay = (float)PropertyManager.GetDouble("encounter_delay").Item; } } wo.EnterWorld(); return(wo); }
/// <summary> /// Monster Locations, Generators<para /> /// This will be called from a separate task from our constructor. Use thread safety when interacting with this landblock. /// </summary> private void CreateWorldObjects() { var objects = DatabaseManager.World.GetCachedInstancesByLandblock(Id.Landblock); var shardObjects = DatabaseManager.Shard.GetStaticObjectsByLandblock(Id.Landblock); var factoryObjects = WorldObjectFactory.CreateNewWorldObjects(objects, shardObjects); actionQueue.EnqueueAction(new ActionEventDelegate(() => { // for mansion linking var houses = new List <House>(); foreach (var fo in factoryObjects) { WorldObject parent = null; if (fo.WeenieType == WeenieType.House) { var house = fo as House; Houses.Add(house); if (fo.HouseType == HouseType.Mansion) { houses.Add(house); house.LinkedHouses.Add(houses[0]); if (houses.Count > 1) { houses[0].LinkedHouses.Add(house); parent = houses[0]; } } } AddWorldObject(fo); fo.ActivateLinks(objects, shardObjects, parent); if (fo.PhysicsObj != null) { fo.PhysicsObj.Order = 0; } } CreateWorldObjectsCompleted = true; _landblock.SortObjects(); })); }
/// <summary> /// Load Inventory for default items from database table / assignes default objects. /// </summary> private void LoadInventory() { // Load Vendor Inventory from database. if (!inventoryloaded) { foreach (AceObjectInventory item in ShopList) { WorldObject wo = WorldObjectFactory.CreateNewWorldObject(item.WeenieClassId); if (wo != null) { wo.ContainerId = Guid.Full; defaultItemsForSale.Add(wo.Guid, wo); } } inventoryloaded = true; } }
/// <summary> /// On initial load, we will create all of the wielded items as world objects and add to dictionary for management. /// </summary> /// <param name="aceObject"></param> public Container(AceObject aceObject) : base(aceObject) { CoinValue = 0; log.Debug($"{aceObject.Name} CoinValue initialized to {CoinValue}"); Burden = 0; log.Debug($"{aceObject.Name} Burden initialized to {Burden}"); Burden += Weenie.EncumbranceVal ?? 0; log.Debug($"{aceObject.Name}'s weenie id is {Weenie.WeenieClassId} and its base burden is {Weenie.EncumbranceVal}, added to burden, Burden = {Burden}"); Value = 0; Value += Weenie.Value ?? 0; WieldedObjects = new Dictionary <ObjectGuid, WorldObject>(); foreach (var wieldedItem in WieldedItems) { ObjectGuid woGuid = new ObjectGuid(wieldedItem.Value.AceObjectId); WieldedObjects.Add(woGuid, WorldObjectFactory.CreateWorldObject(wieldedItem.Value)); Burden += wieldedItem.Value.EncumbranceVal; log.Debug($"{aceObject.Name} is wielding {wieldedItem.Value.Name}, adding {wieldedItem.Value.EncumbranceVal}, current Burden = {Burden}"); Value += wieldedItem.Value.Value; } InventoryObjects = new Dictionary <ObjectGuid, WorldObject>(); foreach (var inventoryItem in Inventory) { ObjectGuid woGuid = new ObjectGuid(inventoryItem.Value.AceObjectId); WorldObject wo = WorldObjectFactory.CreateWorldObject(inventoryItem.Value); InventoryObjects.Add(woGuid, wo); Burden += wo.Burden ?? 0; log.Debug($"{aceObject.Name} is has {wo.Name} in inventory, adding {wo.Burden}, current Burden = {Burden}"); Value += wo.Value ?? 0; if (wo.WeenieType == WeenieType.Coin) { CoinValue += wo.Value ?? 0; log.Debug($"{aceObject.Name} is has {wo.Name} in inventory, of WeenieType.Coin, adding {wo.Value}, current CoinValue = {CoinValue}"); } } }
public List <WorldObject> GetCreateList(DestinationType type) { var items = new List <WorldObject>(); foreach (var item in Biota.BiotaPropertiesCreateList.Where(x => x.DestinationType == (int)type)) { var wo = WorldObjectFactory.CreateNewWorldObject(item.WeenieClassId); if (item.StackSize > 0) { wo.StackSize = (ushort)item.StackSize; } items.Add(wo); } return(items); }
private List <WorldObject> CollectCurrencyStacks(uint currencyWcid, uint amount) { var currencyStacksCollected = new List <WorldObject>(); var currencyStacksInInventory = GetInventoryItemsOfWCID(currencyWcid); //currencyStacksInInventory = currencyStacksInInventory.OrderBy(o => o.Value).ToList(); var remaining = (int)amount; foreach (var stack in currencyStacksInInventory) { var amountToRemove = Math.Min(remaining, stack.StackSize ?? 1); if (stack.StackSize == amountToRemove) { currencyStacksCollected.Add(stack); } else { // create new stack var newStack = WorldObjectFactory.CreateNewWorldObject(currencyWcid); newStack.SetStackSize(amountToRemove); currencyStacksCollected.Add(newStack); var stackToAdjust = FindObject(stack.Guid, SearchLocations.MyInventory, out var foundInContainer, out var rootContainer, out _); // adjust existing stack if (stackToAdjust != null) { AdjustStack(stackToAdjust, -amountToRemove, foundInContainer, rootContainer); Session.Network.EnqueueSend(new GameMessageSetStackSize(stackToAdjust)); Session.Network.EnqueueSend(new GameMessagePrivateUpdatePropertyInt(this, PropertyInt.EncumbranceVal, EncumbranceVal ?? 0)); } // UpdateCoinValue removed -- already called upstream } remaining -= amountToRemove; if (remaining <= 0) { break; } } return(currencyStacksCollected); }
public House LoadHouse(bool forceLoad = false) { if (House != null && !forceLoad) { return(House); } var houseGuid = HouseInstance.Value; var landblock = (ushort)((houseGuid >> 12) & 0xFFFF); var biota = DatabaseManager.Shard.GetBiota(houseGuid); var instances = DatabaseManager.World.GetCachedInstancesByLandblock(landblock); if (instances == null || instances.Count == 0 || biota == null) { Console.WriteLine($"{Name} sent HouseInstance={HouseInstance:X8}, instances={instances}, biota={biota}"); return(null); } var objects = WorldObjectFactory.CreateNewWorldObjects(instances, new List <Biota>() { biota }, houseGuid); if (objects.Count == 0) { Console.WriteLine($"{Name} sent HouseInstance={HouseInstance:X8}, found instances and biota, but object count=0"); return(null); } var house = objects[0] as House; if (house == null) { Console.WriteLine($"{Name} sent HouseInstance={HouseInstance:X8}, found instances and biota, but type {objects[0].WeenieType}"); return(null); } house.ActivateLinks(instances, new List <Biota>() { biota }); House = house; return(house); }
private List <WorldObject> CollectCurrencyStacks(uint currencyWeenieClassId, uint amountToSpend) { var currencyStacksCollected = new List <WorldObject>(); var currencyStacksInInventory = GetInventoryItemsOfWCID(currencyWeenieClassId); currencyStacksInInventory = currencyStacksInInventory.OrderBy(o => o.Value).ToList(); var leftToCollect = (int)amountToSpend; foreach (var stack in currencyStacksInInventory) { var amountToRemove = Math.Min(leftToCollect, stack.StackSize ?? 1); if (stack.StackSize == amountToRemove) { currencyStacksCollected.Add(stack); } else { var newStack = WorldObjectFactory.CreateNewWorldObject(currencyWeenieClassId); newStack.SetStackSize(amountToRemove); currencyStacksCollected.Add(newStack); var stackToAdjust = FindObject(stack.Guid, SearchLocations.MyInventory, out var foundInContainer, out var rootContainer, out _); if (stackToAdjust != null) { AdjustStack(stackToAdjust, -amountToRemove, foundInContainer, rootContainer); Session.Network.EnqueueSend(new GameMessageSetStackSize(stackToAdjust)); Session.Network.EnqueueSend(new GameMessagePrivateUpdatePropertyInt(this, PropertyInt.EncumbranceVal, EncumbranceVal ?? 0)); if (stackToAdjust.WeenieType == WeenieType.Coin) { UpdateCoinValue(); } } } leftToCollect -= amountToRemove; if (leftToCollect <= 0) { break; } } return(currencyStacksCollected); }
public Landblock(LandblockId id) { this.id = id; UpdateStatus(LandBlockStatusFlag.IdleUnloaded); // initialize adjacency array adjacencies.Add(Adjacency.North, null); adjacencies.Add(Adjacency.NorthEast, null); adjacencies.Add(Adjacency.East, null); adjacencies.Add(Adjacency.SouthEast, null); adjacencies.Add(Adjacency.South, null); adjacencies.Add(Adjacency.SouthWest, null); adjacencies.Add(Adjacency.West, null); adjacencies.Add(Adjacency.NorthWest, null); UpdateStatus(LandBlockStatusFlag.IdleLoading); actionQueue = new NestedActionQueue(WorldManager.ActionQueue); // TODO: Load cell.dat contents // 1. landblock cell structure // 2. terrain data // TODO: Load portal.dat contents (as/if needed) // TODO: Load spawn data var objects = DatabaseManager.World.GetObjectsByLandblock(this.id.Landblock); var factoryObjects = WorldObjectFactory.CreateWorldObjects(objects); factoryObjects.ForEach(fo => { if (!worldObjects.ContainsKey(fo.Guid)) { worldObjects.Add(fo.Guid, fo); fo.SetParent(this); } }); UpdateStatus(LandBlockStatusFlag.IdleLoaded); // FIXME(ddevec): Goal: get rid of UseTime() function... actionQueue.EnqueueAction(new ActionEventDelegate(() => UseTimeWrapper())); motionQueue = new NestedActionQueue(WorldManager.MotionQueue); }
public static WorldObject CreateItem(Player player, uint wcid, uint amount) { var wo = WorldObjectFactory.CreateNewWorldObject(wcid); if (wo == null) { log.Warn($"RecipeManager.CreateItem({player.Name}, {wcid}, {amount}): failed to create {wcid}"); return(null); } if (amount > 1) { wo.StackSize = (ushort)amount; } player.TryCreateInInventoryWithNetworking(wo); return(wo); }