public override void Execute(System.Collections.Generic.List <string> _params, CommandSenderInfo _senderInfo) { if (_params.Count != 1) { SdtdConsole.Instance.Output("[ResetTrader] Invalid Parameter Length"); return; } int entityId = -1; int.TryParse(_params [0], out entityId); if (entityId > -1) { Entity ent = GameManager.Instance.World.GetEntity(entityId); if (ent is EntityNPC) { EntityNPC trader = ent as EntityNPC; TileEntityTrader te = trader.TileEntityTrader; if (te != null) { Log.Out(te.TraderData.AvailableMoney + " dukes"); te.TraderData.PrimaryInventory = new List <ItemStack> (); te.TraderData.TierItemGroups = new List <ItemStack[]> (); te.SetModified(); } } } }
public BCMTileEntityTrader(Vector3i pos, TileEntityTrader te) : base(pos, te) { Money = te.TraderData.AvailableMoney; ResetTime = te.TraderData.NextResetTime; TraderId = te.TraderData.TraderID; IsOpen = te.TraderData.TraderInfo.IsOpen; PlayerOwned = te.TraderData.TraderInfo.PlayerOwned; foreach (var itemStack in te.TraderData.PrimaryInventory) { Inventory.Add(new BCMItemStack(itemStack)); } foreach (var tierGroup in te.TraderData.TierItemGroups) { TierGroups.Add(tierGroup.Select(itemStack => new BCMItemStack(itemStack)).ToList()); } }
public void SetHistory(TileEntityTrader _te) { this.lastPrimaryInventory = this.PrimaryInventory; this.lastTierGroupItems = this.TierGroupItems; this.PrimaryInventory.Clear(); this.TierGroupItems.Clear(); foreach (ItemStack itemStack in _te.TraderData.PrimaryInventory) { this.PrimaryInventory.Add(itemStack); } foreach (ItemStack[] items in _te.TraderData.TierItemGroups) { this.TierGroupItems.Add(items); } }
internal void Read(BinaryReader reader) { Utils.VerifyVersion(reader.ReadByte(), SaveVersionConstants.ENTITY_CREATION_DATA); entityClass = new Value <int>(reader.ReadInt32()); id = new Value <int>(reader.ReadInt32()); lifetime = new Value <float>(reader.ReadSingle()); pos = new Vector3D <float> { x = new Value <float>(reader.ReadSingle()), y = new Value <float>(reader.ReadSingle()), z = new Value <float>(reader.ReadSingle()) }; rot = new Vector3D <float> { x = new Value <float>(reader.ReadSingle()), y = new Value <float>(reader.ReadSingle()), z = new Value <float>(reader.ReadSingle()) }; onGround = new Value <bool>(reader.ReadBoolean()); bodyDamage = new BodyDamage(reader); if (reader.ReadBoolean()) { stats = new EntityStats(reader); } deathTime = new Value <short>(reader.ReadInt16()); if (reader.ReadBoolean()) { int tileEntityType = reader.ReadInt32(); lootContainer = TileEntity.Instantiate((TileEntityType)(tileEntityType)); lootContainer.Read(reader); } homePosition = new Vector3D <int> { x = new Value <int>(reader.ReadInt32()), y = new Value <int>(reader.ReadInt32()), z = new Value <int>(reader.ReadInt32()) }; homeRange = new Value <short>(reader.ReadInt16()); spawnerSource = (EnumSpawnerSource)reader.ReadByte(); if (entityClass.Get() == Utils.GetMonoHash("item")) { belongsPlayerId = new Value <int>(reader.ReadInt32()); itemStack.Read(reader); reader.ReadSByte(); } else if (entityClass.Get() == Utils.GetMonoHash("fallingBlock")) { blockValue = new Value <uint>(reader.ReadUInt32()); textureFull = new Value <long>(reader.ReadInt64()); } else if (entityClass.Get() == Utils.GetMonoHash("fallingTree")) { blockPosition = new Vector3D <int> { x = new Value <int>(reader.ReadInt32()), y = new Value <int>(reader.ReadInt32()), z = new Value <int>(reader.ReadInt32()) }; fallTreeDir = new Vector3D <float> { x = new Value <float>(reader.ReadSingle()), y = new Value <float>(reader.ReadSingle()), z = new Value <float>(reader.ReadSingle()) }; } else if ((entityClass.Get() == Utils.GetMonoHash("playerMale")) || (entityClass.Get() == Utils.GetMonoHash("playerFemale"))) { holdingItem = new ItemValue(reader); teamNumber = new Value <byte>(reader.ReadByte()); entityName = new Value <string>(reader.ReadString()); skinTexture = new Value <string>(reader.ReadString()); if (reader.ReadBoolean()) { playerProfile = PlayerProfile.Read(reader); } else { playerProfile = null; } } //num2 ushort entityDataLength = reader.ReadUInt16(); if (entityDataLength > 0) { byte[] buffer = reader.ReadBytes(entityDataLength); entityData = new MemoryStream(buffer); } if (reader.ReadBoolean()) { int tileEntityType = reader.ReadInt32(); traderData = (TileEntityTrader)TileEntity.Instantiate((TileEntityType)(tileEntityType)); traderData.Read(reader); } }
public override void OnUpdateLive() { // Wake them up if they are sleeping, since the trigger sleeper makes them go idle again. if (!this.sleepingOrWakingUp && isAlwaysAwake) { this.IsSleeping = true; ConditionalTriggerSleeperWakeUp(); } emodel.avatarController.SetBool("IsBusy", false); Buffs.RemoveBuff("buffnewbiecoat", false); Stats.Health.MaxModifier = Stats.Health.Max; // Set CanFall and IsOnGround if (this.emodel != null && this.emodel.avatarController != null) { this.emodel.avatarController.SetBool("CanFall", !this.emodel.IsRagdollActive && this.bodyDamage.CurrentStun == EnumEntityStunType.None && !this.isSwimming); this.emodel.avatarController.SetBool("IsOnGround", this.onGround || this.isSwimming); } if (SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer) { //If blocked, check to see if its a door. if (moveHelper.IsBlocked) { Vector3i blockPos = moveHelper.HitInfo.hit.blockPos; BlockValue block = world.GetBlock(blockPos); if (Block.list[block.type].HasTag(BlockTags.Door) && !BlockDoor.IsDoorOpen(block.meta)) { bool canOpenDoor = true; TileEntitySecureDoor tileEntitySecureDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntitySecureDoor; if (tileEntitySecureDoor != null) { if (tileEntitySecureDoor.IsLocked() && tileEntitySecureDoor.GetOwner() == "") { canOpenDoor = false; } } //TileEntityPowered poweredDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntityPowered; //if (poweredDoor != null) //{ // if (poweredDoor.IsLocked() && poweredDoor.GetOwner() == "") // canOpenDoor = false; //} if (canOpenDoor) { DisplayLog("I am blocked by a door. Trying to open..."); SphereCache.AddDoor(entityId, blockPos); EntityUtilities.OpenDoor(entityId, blockPos); // We were blocked, so let's clear it. moveHelper.ClearBlocked(); } } } } // Check to see if we've opened a door, and close it behind you. Vector3i doorPos = SphereCache.GetDoor(entityId); if (doorPos != Vector3i.zero) { DisplayLog("I've opened a door recently. I'll see if I can close it."); BlockValue block = world.GetBlock(doorPos); if (Block.list[block.type].HasTag(BlockTags.Door) && BlockDoor.IsDoorOpen(block.meta)) { float CloseDistance = 3; // If it's a multidim, increase tha radius a bit if (Block.list[block.type].isMultiBlock) { Vector3i vector3i = StringParsers.ParseVector3i(Block.list[block.type].Properties.Values["MultiBlockDim"], 0, -1, false); if (CloseDistance > vector3i.x) { CloseDistance = vector3i.x + 1; } } if ((GetDistanceSq(doorPos.ToVector3()) > CloseDistance)) { DisplayLog("I am going to close the door now."); EntityUtilities.CloseDoor(entityId, doorPos); SphereCache.RemoveDoor(entityId, doorPos); } } } // Makes the NPC always face its attack or revent target. EntityAlive target = EntityUtilities.GetAttackOrReventTarget(entityId) as EntityAlive; if (target != null) { // makes the npc look at its attack target if (this.emodel != null && this.emodel.avatarController != null) { this.emodel.SetLookAt(target.getHeadPosition()); } SetLookPosition(target.getHeadPosition()); RotateTo(target, 45, 45); if (EntityUtilities.HasTask(this.entityId, "Ranged")) { if (EntityUtilities.CheckAIRange(this.entityId, target.entityId)) { EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Ranged); } else { EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Melee); } } else { EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Melee); } } // Non-player entities don't fire all the buffs or stats, so we'll manually fire the water tick, // Stats.Water.Tick(0.5f, 0, false); // then fire the updatestats over time, which is protected from a IsPlayer check in the base onUpdateLive(). //Stats.UpdateStatsOverTime(0.5f); updateTime = Time.time + 2f; base.OnUpdateLive(); // Allow EntityAliveSDX to get buffs from blocks if (!this.isEntityRemote) { updateBlockRadiusEffects(); } // No NPC info, don't continue if (NPCInfo == null) { return; } // If the Tile Entity Trader isn't set, set it now. Sometimes this fails, and won't allow interaction. if (TileEntityTrader == null) { TileEntityTrader = new TileEntityTrader(null); TileEntityTrader.entityId = entityId; TileEntityTrader.TraderData.TraderID = NPCInfo.TraderID; } // If there is no attack target, don't bother checking this. if (target == null) { if (this is EntityAliveFarmingAnimalSDX) { return; } List <global::Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(this, new Bounds(position, Vector3.one * 5f)); if (entitiesInBounds.Count > 0) { for (int i = 0; i < entitiesInBounds.Count; i++) { if (entitiesInBounds[i] is EntityPlayerLocal || entitiesInBounds[i] is EntityPlayer) { // Check your faction relation. If you hate each other, don't stop and talk. FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(this, entitiesInBounds[i] as EntityPlayerLocal); if (myRelationship == FactionManager.Relationship.Hate) { break; } if (GetDistance(entitiesInBounds[i]) < 1 && this.moveHelper != null) { DisplayLog("The entity is too close to me. Moving away: " + entitiesInBounds[i].ToString()); EntityUtilities.BackupHelper(entityId, entitiesInBounds[i].position, 3); break; } // Turn to face the player, and stop the movement. emodel.avatarController.SetBool("IsBusy", true); SetLookPosition(entitiesInBounds[i].getHeadPosition()); RotateTo(entitiesInBounds[i], 90f, 90f); EntityUtilities.Stop(this.entityId); break; } } } } }
public void OnTileEntityChanged(TileEntity _te, int _dataObject) { if (_te == null) { return; } TileEntityTrader npc = _te as TileEntityTrader; bool primaryChanged = false; bool stashChanged = false; //check for inventory changes if (npc.TraderData.PrimaryInventory.Count != this.PrimaryInventory.Count) { //certainly have a change primaryChanged = true; } else { //check to make sure everything is still the same for (int i = 0; i < npc.TraderData.PrimaryInventory.Count; i++) { ItemStack oldItem = this.PrimaryInventory [i]; ItemStack currentItem = npc.TraderData.PrimaryInventory [i]; if (oldItem.itemValue.type != currentItem.itemValue.type || oldItem.count != currentItem.count) { primaryChanged = true; break; } } } if (npc.TraderData.TierItemGroups.Count != this.TierGroupItems.Count) { stashChanged = true; } else { for (int grp = 0; grp < npc.TraderData.TierItemGroups.Count; grp++) { ItemStack[] oldItemGroup = this.TierGroupItems [grp]; ItemStack[] itemGroup = npc.TraderData.TierItemGroups [grp]; for (int i = 0; i < itemGroup.Length; i++) { if (oldItemGroup [i].itemValue.type != itemGroup [i].itemValue.type || oldItemGroup [i].count != itemGroup [i].count) { stashChanged = true; break; } } } } Entity e = GameManager.Instance.World.GetEntity(_te.entityId); if (primaryChanged) { API.Events.NotifyTraderPrimaryInventoryChangedHandlers(e as EntityNPC, this.lastPrimaryInventory); } if (stashChanged) { API.Events.NotifyTraderSecretStashChangedHandlers(e as EntityNPC, this.lastTierGroupItems); } SetHistory(npc); Log.Out(_te.GetTileEntityType().ToString() + " - " + primaryChanged); }
public TENPCChangedHandler(TileEntityTrader _te) { SetHistory(_te); }
public override void OnUpdateLive() { //If blocked, check to see if its a door. if (moveHelper.IsBlocked) { Vector3i blockPos = moveHelper.HitInfo.hit.blockPos; BlockValue block = world.GetBlock(blockPos); if (Block.list[block.type].HasTag(BlockTags.Door) && !BlockDoor.IsDoorOpen(block.meta)) { bool canOpenDoor = true; TileEntitySecureDoor tileEntitySecureDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntitySecureDoor; if (tileEntitySecureDoor != null) { if (tileEntitySecureDoor.IsLocked() && tileEntitySecureDoor.GetOwner() == "") { canOpenDoor = false; } } //TileEntityPowered poweredDoor = GameManager.Instance.World.GetTileEntity(0, blockPos) as TileEntityPowered; //if (poweredDoor != null) //{ // if (poweredDoor.IsLocked() && poweredDoor.GetOwner() == "") // canOpenDoor = false; //} if (canOpenDoor) { DisplayLog("I am blocked by a door. Trying to open..."); SphereCache.AddDoor(entityId, blockPos); EntityUtilities.OpenDoor(entityId, blockPos); // We were blocked, so let's clear it. moveHelper.ClearBlocked(); } } } // Check to see if we've opened a door, and close it behind you. Vector3i doorPos = SphereCache.GetDoor(entityId); if (doorPos != Vector3i.zero) { DisplayLog("I've opened a door recently. I'll see if I can close it."); BlockValue block = world.GetBlock(doorPos); if (Block.list[block.type].HasTag(BlockTags.Door) && BlockDoor.IsDoorOpen(block.meta)) { float CloseDistance = 3; // If it's a multidim, increase tha radius a bit if (Block.list[block.type].isMultiBlock) { Vector3i vector3i = StringParsers.ParseVector3i(Block.list[block.type].Properties.Values["MultiBlockDim"], 0, -1, false); if (CloseDistance > vector3i.x) { CloseDistance = vector3i.x + 1; } } if ((GetDistanceSq(doorPos.ToVector3()) > CloseDistance)) { DisplayLog("I am going to close the door now."); EntityUtilities.CloseDoor(entityId, doorPos); SphereCache.RemoveDoor(entityId, doorPos); } } } // Makes the NPC always face its attack or revent target. EntityAlive target = EntityUtilities.GetAttackOrReventTarget(entityId) as EntityAlive; if (target != null) { SetLookPosition(attackTarget.position); RotateTo(attackTarget, 45, 45); } Buffs.RemoveBuff("buffnewbiecoat", false); Stats.Health.MaxModifier = Stats.Health.Max; // Non-player entities don't fire all the buffs or stats, so we'll manually fire the water tick, Stats.Water.Tick(0.5f, 0, false); // then fire the updatestats over time, which is protected from a IsPlayer check in the base onUpdateLive(). Stats.UpdateStatsOverTime(0.5f); updateTime = Time.time - 2f; base.OnUpdateLive(); // No NPC info, don't continue if (NPCInfo == null) { return; } // If the Tile Entity Trader isn't set, set it now. Sometimes this fails, and won't allow interaction. if (TileEntityTrader == null) { TileEntityTrader = new TileEntityTrader(null); TileEntityTrader.entityId = entityId; TileEntityTrader.TraderData.TraderID = NPCInfo.TraderID; } // Check if there's a player within 10 meters of us. If not, resume wandering. emodel.avatarController.SetBool("IsBusy", false); if (!SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer) { return; } if (target == null) { if (this is EntityAliveFarmingAnimalSDX) { return; } List <global::Entity> entitiesInBounds = GameManager.Instance.World.GetEntitiesInBounds(this, new Bounds(position, Vector3.one * 5f)); if (entitiesInBounds.Count > 0) { for (int i = 0; i < entitiesInBounds.Count; i++) { if (entitiesInBounds[i] is EntityPlayerLocal) { // Check your faction relation. If you hate each other, don't stop and talk. FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(this, entitiesInBounds[i] as EntityPlayerLocal); if (myRelationship == FactionManager.Relationship.Hate) { break; } if (GetDistance(entitiesInBounds[i]) < 2) { DisplayLog("The entity is too close to me. Moving away: " + entitiesInBounds[i].ToString()); EntityUtilities.BackupHelper(entityId, entitiesInBounds[i].position, 5); //moveHelper.SetMoveTo((entitiesInBounds[i] as EntityPlayerLocal).GetLookVector(), false); break; } // Turn to face the player, and stop the movement. emodel.avatarController.SetBool("IsBusy", true); SetLookPosition(entitiesInBounds[i].getHeadPosition()); RotateTo(entitiesInBounds[i], 90f, 90f); navigator.clearPath(); moveHelper.Stop(); // this stops the walking jitter this.speedForward = 0; break; } } } } }