public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { if (notplucking && itemslot.Empty) { notplucking = false; ItemStack feather = new ItemStack(entity.World.GetItem(new AssetLocation("game:feather")), 1); feather.StackSize = entity.World.Rand.Next(1, 2); source.sourcePos = hitPosition; source.SourceEntity = byEntity; entity.ReceiveDamage(source, (float)((entity.World.Rand.NextDouble() * 0.25) / 2)); if (byEntity.World.Side.IsServer()) { if (!byEntity.TryGiveItemStack(feather)) { entity.World.SpawnItemEntity(feather, entity.Pos.XYZ); } } entity.World.RegisterCallback(dt => { notplucking = true; }, 2000); } }
public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { base.OnInteract(byEntity, itemslot, hitPosition, mode, ref handled); IPlayer byPlayer = byEntity.World.PlayerByUid((byEntity as EntityPlayer).PlayerUID); if (owner != null && owner != byPlayer) { return; } if (mode == EnumInteractMode.Interact) { if (byEntity.Controls.Sneak && byEntity.Controls.Sprint && !invLocked) { workInv[0].TryFlipWith(itemslot); return; } if (itemslot.Itemstack?.Collectible is ItemHammer) { if (entity.GetBehavior <EntityBehaviorHealth>()?.Health < entity.GetBehavior <EntityBehaviorHealth>()?.MaxHealth) { itemslot.Itemstack.Collectible.DamageItem(entity.World, byEntity, itemslot, 5); entity.World.PlaySoundAt(new AssetLocation("game:sounds/effect/anvilhit3.ogg"), entity, byPlayer); entity.ReceiveDamage(new DamageSource() { Type = EnumDamageType.Heal }, 1); return; } } if (byEntity.Controls.Sprint && !restricted && itemslot?.Itemstack?.Collectible is ItemProgCard) { ItemStack stack = itemslot.Itemstack.Attributes.GetItemstack("workStack"); if (stack == null) { return; } stack.ResolveBlockOrItem(entity.World); if (stack != null) { workInv.DropAll(entity.ServerPos.XYZ); workStack = stack; maintree.SetItemstack("workStack", workStack); (byPlayer as IServerPlayer)?.SendMessage(GlobalConstants.InfoLogChatGroup, Lang.Get("temporalhack:work-itemprogram"), EnumChatType.Notification); } return; } else if (byEntity.Controls.Sprint && itemslot.Empty && byPlayer != null && workArea != null) { BlockPos min = workArea.Start.AsBlockPos; BlockPos max = workArea.End.AsBlockPos; max.Y += 1; List <BlockPos> blocks = new List <BlockPos>() { min, max }; List <int> colors = new List <int>() { ColorUtil.ColorFromRgba(215, 94, 94, 64), ColorUtil.ColorFromRgba(215, 94, 94, 64) }; entity.Api.World.HighlightBlocks(byPlayer, 56, blocks, colors, EnumHighlightBlocksMode.Absolute, EnumHighlightShape.Cube); entity.Api.World.RegisterCallback((dt) => entity.Api.World.HighlightBlocks(byPlayer, 56, new List <BlockPos>(), new List <int>()), 3000); } if (byEntity.Controls.Sneak && itemslot?.Itemstack?.Collectible is ItemProgCard) { ITreeAttribute area = itemslot.Itemstack.Attributes.GetTreeAttribute("workArea"); ITreeAttribute box = null; ITreeAttribute barrel = null; if (!nochest) { box = itemslot.Itemstack.Attributes.GetTreeAttribute("workChest"); } if (!nobarrel) { barrel = itemslot.Itemstack.Attributes.GetTreeAttribute("workBarrel"); } StopAll(); if (area != null) { maintree["workArea"] = area.Clone(); workArea = cuboiddFromTree(area); } if (box != null) { maintree["workChest"] = box.Clone(); workChest = new BlockPos(box.GetInt("x"), box.GetInt("y"), box.GetInt("z")); } if (barrel != null) { maintree["workBarrel"] = barrel.Clone(); workBarrel = new BlockPos(barrel.GetInt("x"), barrel.GetInt("y"), barrel.GetInt("z")); } if (area != null || box != null || barrel != null) { (byPlayer as IServerPlayer)?.SendMessage(GlobalConstants.InfoLogChatGroup, Lang.Get("temporalhack:work-program"), EnumChatType.Notification); } } else if (byEntity.Controls.Sneak && itemslot.Empty) { AssetLocation item = new AssetLocation(entity.Code.Domain, "deploybot-" + entity.Code.Path); if (item != null) { EntityBehaviorHealth bh = entity.GetBehavior <EntityBehaviorHealth>(); ItemStack stack = new ItemStack(entity.World.GetItem(item)); stack.Attributes.SetInt("workEnergy", energy); if (bh != null) { stack.Attributes.SetFloat("workHealth", bh.MaxHealth - bh.Health); } byEntity.World.SpawnItemEntity(stack, entity.SidedPos.XYZ); workInv.DropAll(entity.ServerPos.XYZ); entity.Die(EnumDespawnReason.Removed); } } else if (byEntity.Controls.Sneak && itemslot?.Itemstack?.Collectible?.CombustibleProps?.BurnDuration != null) { if (itemslot.Itemstack.Collectible.CombustibleProps.BurnTemperature >= 200) { AddEnergy((itemslot.Itemstack.Collectible.CombustibleProps.BurnTemperature / 100) * (int)itemslot.Itemstack.Collectible.CombustibleProps.BurnDuration); itemslot.TakeOut(1); entity.World.PlaySoundAt(new AssetLocation("game:sounds/effect/extinguish2.ogg"), entity, byPlayer); } } } else { if (byEntity.Controls.Sneak) { StopAll(); workStack = null; workInv.DropAll(entity.ServerPos.XYZ); RemoveArea(); RemoveBarrel(); RemoveChest(); (byPlayer as IServerPlayer)?.SendMessage(GlobalConstants.InfoLogChatGroup, Lang.Get("temporalhack:work-memoryloss"), EnumChatType.Notification); } } }
public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { if (itemslot.Itemstack == null) { return; } if (itemslot.Itemstack.Block is BlockBucket) { handled = EnumHandling.PreventDefault; ItemStack milkstack = new ItemStack(milk); BlockBucket bucket = itemslot.Itemstack.Block as BlockBucket; ItemStack contents = bucket.GetContent(byEntity.World, itemslot.Itemstack); if ((contents == null || contents.Item == milk) && RemainingLiters > 0) { if (bucket.TryPutContent(byEntity.World, itemslot.Itemstack, milkstack, 1) > 0) { RemainingLiters -= 1; if (byEntity.World.Side == EnumAppSide.Client) { byEntity.World.SpawnCubeParticles(entity.Pos.XYZ + new Vec3d(0, 0.5, 0), milkstack, 0.3f, 4, 0.5f, (byEntity as EntityPlayer)?.Player); } if (id == 0 && RemainingLiters < defaultvalue) { if (NextTimeMilkable == 0) { NextTimeMilkable = GetNextTimeMilkable(); } id = entity.World.RegisterGameTickListener(MilkListener, 1000); } itemslot.MarkDirty(); } } } base.OnInteract(byEntity, itemslot, hitPosition, mode, ref handled); }
public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { IPlayer plr = (byEntity as EntityPlayer)?.Player; if (plr != null && !byEntity.World.Claims.TryAccess(plr, Pos.AsBlockPos, EnumBlockAccessFlags.Use)) { plr.InventoryManager.ActiveHotbarSlot.MarkDirty(); WatchedAttributes.MarkAllDirty(); return; } if (mode == EnumInteractMode.Interact && byEntity.RightHandItemSlot != null) { ItemSlot handslot = byEntity.RightHandItemSlot; if (handslot.Empty) { // Start from armor slot because it can't wear clothes atm for (int i = 0; i < GearInventory.Count; i++) { ItemSlot gslot = GearInventory[i]; if (gslot.Empty) { continue; } if (gslot.TryPutInto(byEntity.World, handslot) > 0) { return; } } } else { if (!ItemSlotCharacter.IsDressType(slot.Itemstack, EnumCharacterDressType.ArmorBody) && !ItemSlotCharacter.IsDressType(slot.Itemstack, EnumCharacterDressType.ArmorHead) && !ItemSlotCharacter.IsDressType(slot.Itemstack, EnumCharacterDressType.ArmorLegs)) { (byEntity.World.Api as ICoreClientAPI)?.TriggerIngameError(this, "cantplace", "Cannot place dresses on armor stands"); return; } } WeightedSlot sinkslot = GearInventory.GetBestSuitedSlot(handslot); if (sinkslot.weight > 0 && sinkslot.slot != null) { handslot.TryPutInto(byEntity.World, sinkslot.slot); return; } bool empty = true; for (int i = 0; i < GearInventory.Count; i++) { ItemSlot gslot = GearInventory[i]; empty &= gslot.Empty; } if (empty && byEntity.Controls.Sneak) { ItemStack stack = new ItemStack(byEntity.World.GetItem(new AssetLocation("armorstand"))); if (!byEntity.TryGiveItemStack(stack)) { byEntity.World.SpawnItemEntity(stack, ServerPos.XYZ); } Die(); return; } } if (!Alive || World.Side == EnumAppSide.Client || mode == 0) { //base.OnInteract(byEntity, slot, hitPosition, mode); return; } base.OnInteract(byEntity, slot, hitPosition, mode); }
public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { EnumHandling handled = EnumHandling.PassThrough; foreach (EntityBehavior behavior in SidedProperties.Behaviors) { behavior.OnInteract(byEntity, slot, hitPosition, mode, ref handled); if (handled == EnumHandling.PreventSubsequent) { break; } } if (handled == EnumHandling.PreventDefault || handled == EnumHandling.PreventSubsequent) { return; } if (mode == EnumInteractMode.Attack) { float damage = slot.Itemstack == null ? 0.5f : slot.Itemstack.Collectible.GetAttackPower(slot.Itemstack); int damagetier = slot.Itemstack == null ? 0 : slot.Itemstack.Collectible.ToolTier; damage *= byEntity.Stats.GetBlended("meleeWeaponsDamage"); if (Attributes.GetBool("isMechanical", false)) { damage *= byEntity.Stats.GetBlended("mechanicalsDamage"); } IPlayer byPlayer = null; if (byEntity is EntityPlayer && !IsActivityRunning("invulnerable")) { byPlayer = (byEntity as EntityPlayer).Player; World.PlaySoundAt(new AssetLocation("sounds/player/slap"), ServerPos.X, ServerPos.Y, ServerPos.Z, byPlayer); slot?.Itemstack?.Collectible.OnAttackingWith(byEntity.World, byEntity, this, slot); } if (Api.Side == EnumAppSide.Client && damage > 1 && !IsActivityRunning("invulnerable") && Properties.Attributes?["spawnDamageParticles"].AsBool() == true) { Vec3d pos = SidedPos.XYZ + hitPosition; Vec3d minPos = pos.AddCopy(-0.15, -0.15, -0.15); Vec3d maxPos = pos.AddCopy(0.15, 0.15, 0.15); int textureSubId = this.Properties.Client.FirstTexture.Baked.TextureSubId; Vec3f tmp = new Vec3f(); for (int i = 0; i < 10; i++) { int color = (Api as ICoreClientAPI).EntityTextureAtlas.GetRandomColor(textureSubId); tmp.Set( 1f - 2 * (float)World.Rand.NextDouble(), 2 * (float)World.Rand.NextDouble(), 1f - 2 * (float)World.Rand.NextDouble() ); World.SpawnParticles( 1, color, minPos, maxPos, tmp, tmp, 1.5f, 1f, 0.25f + (float)World.Rand.NextDouble() * 0.25f, EnumParticleModel.Cube, byPlayer ); } } DamageSource dmgSource = new DamageSource() { Source = (byEntity as EntityPlayer).Player == null ? EnumDamageSource.Entity : EnumDamageSource.Player, SourceEntity = byEntity, Type = EnumDamageType.BluntAttack, HitPosition = hitPosition, DamageTier = damagetier }; if (ReceiveDamage(dmgSource, damage)) { byEntity.DidAttack(dmgSource, this); } } }
public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { base.OnInteract(byEntity, slot, hitPosition, mode); if ((byEntity as EntityPlayer)?.Controls.Sneak == true && mode == EnumInteractMode.Interact && byEntity.World.Side == EnumAppSide.Server) { inv.DiscardAll(); WatchedAttributes.MarkAllDirty(); } }
public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { bool inRange = (byEntity.World.Side == EnumAppSide.Client && byEntity.Pos.SquareDistanceTo(entity.Pos) <= 5) || (byEntity.World.Side == EnumAppSide.Server && byEntity.Pos.SquareDistanceTo(entity.Pos) <= 14); if (!IsHarvested || !inRange) { return; } EntityPlayer entityplr = byEntity as EntityPlayer; IPlayer player = entity.World.PlayerByUid(entityplr.PlayerUID); player.InventoryManager.OpenInventory(inv); if (entity.World.Side == EnumAppSide.Client && dlg == null) { dlg = new GuiDialogCarcassContents(inv, entity as EntityAgent, entity.Api as ICoreClientAPI); if (dlg.TryOpen()) { (entity.World.Api as ICoreClientAPI).Network.SendPacketClient(inv.Open(player)); } dlg.OnClosed += () => dlg = null; } }
public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { if (mode != EnumInteractMode.Interact || !(byEntity is EntityPlayer)) { base.OnInteract(byEntity, slot, hitPosition, mode); return; } if (!Alive) { return; } EntityPlayer entityplr = byEntity as EntityPlayer; IPlayer player = World.PlayerByUid(entityplr.PlayerUID); player.InventoryManager.OpenInventory(Inventory); tradingWith = entityplr; if (World.Side == EnumAppSide.Client) { if (tradingWith.Pos.SquareDistanceTo(this.Pos) <= 5 && dlg?.IsOpened() != true) { dlg = new GuiDialogTrader(Inventory, this, World.Api as ICoreClientAPI); dlg.TryOpen(); dlg.OnClosed += () => tradingWith = null; } talkUtil.Talk(EnumTalkType.Meet); } if (World.Side == EnumAppSide.Server) { // Make the trader walk towards the player AiTaskManager tmgr = GetBehavior <EntityBehaviorTaskAI>().taskManager; tmgr.StopTask(typeof(AiTaskWander)); AiTaskGotoEntity task = new AiTaskGotoEntity(this, entityplr); if (task.TargetReached()) { tmgr.ExecuteTask(new AiTaskLookAtEntity(this, entityplr), 1); } else { tmgr.ExecuteTask(task, 1); } AnimManager.StopAnimation("idle"); AnimManager.StartAnimation(new AnimationMetaData() { Animation = "welcome", Code = "welcome", Weight = 10, EaseOutSpeed = 10000, EaseInSpeed = 10000 }); } }
public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { Sit = !Sit; }
/// <summary> /// The event fired when the entity is interacted with by the player. /// </summary> /// <param name="byEntity">The entity it was interacted with.</param> /// <param name="itemslot">The item slot involved (if any)</param> /// <param name="hitPosition">The hit position of the entity.</param> /// <param name="mode">The interaction mode for the entity.</param> /// <param name="handled">How this event is handled.</param> public virtual void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { }
public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { if (!Alive || World.Side == EnumAppSide.Client || mode == 0) { base.OnInteract(byEntity, slot, hitPosition, mode); return; } string owneruid = WatchedAttributes.GetString("ownerUid", null); string agentUid = (byEntity as EntityPlayer)?.PlayerUID; if (agentUid != null && (owneruid == null || owneruid == "" || owneruid == agentUid) && byEntity.Controls.Sneak) { ItemStack stack = new ItemStack(byEntity.World.GetItem(new AssetLocation("strawdummy"))); if (!byEntity.TryGiveItemStack(stack)) { byEntity.World.SpawnItemEntity(stack, ServerPos.XYZ); } Die(); return; } base.OnInteract(byEntity, slot, hitPosition, mode); }
public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { if (mode != EnumInteractMode.Interact || !(byEntity is EntityPlayer)) { base.OnInteract(byEntity, slot, hitPosition, mode); return; } if (!Alive) { return; } EntityPlayer entityplr = byEntity as EntityPlayer; IPlayer player = World.PlayerByUid(entityplr.PlayerUID); tradingWith = entityplr; if (World.Side == EnumAppSide.Client) { ICoreClientAPI capi = (ICoreClientAPI)Api; if (tradingWith.Pos.SquareDistanceTo(this.Pos) <= 5 && dlg?.IsOpened() != true) { // Will break all kinds of things if we allow multiple concurrent of these dialogs if (capi.Gui.OpenedGuis.FirstOrDefault(dlg => dlg is GuiDialogTrader && dlg.IsOpened()) == null) { capi.Network.SendEntityPacket(this.EntityId, 1001); player.InventoryManager.OpenInventory(Inventory); dlg = new GuiDialogTrader(Inventory, this, World.Api as ICoreClientAPI); dlg.TryOpen(); } else { capi.TriggerIngameError(this, "onlyonedialog", Lang.Get("Can only trade with one trader at a time")); } } else { // Ensure inventory promptly closed server-side if the client didn't open the GUI capi.Network.SendPacketClient(capi.World.Player.InventoryManager.CloseInventory(Inventory)); } talkUtil.Talk(EnumTalkType.Meet); } if (World.Side == EnumAppSide.Server) { // Make the trader walk towards the player AiTaskManager tmgr = GetBehavior <EntityBehaviorTaskAI>().TaskManager; tmgr.StopTask(typeof(AiTaskWander)); AiTaskGotoEntity task = new AiTaskGotoEntity(this, entityplr); if (task.TargetReached()) { tmgr.ExecuteTask(new AiTaskLookAtEntity(this, entityplr), 1); } else { tmgr.ExecuteTask(task, 1); } AnimManager.StartAnimation(new AnimationMetaData() { Animation = "welcome", Code = "welcome", Weight = 10, EaseOutSpeed = 10000, EaseInSpeed = 10000 }); AnimManager.StopAnimation("idle"); } }
public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode, ref EnumHandling handled) { var clothids = ClothIds; if (clothids == null || clothids.value.Length == 0) { return; } int clothid = ClothIds.value[0]; ClothIds.RemoveInt(clothid); var sys = byEntity.World.Api.ModLoader.GetModSystem <ClothManager>().GetClothSystem(clothid); if (sys != null) { Detach(sys); var ends = sys.Ends; Vec3d lpos = new Vec3d(0, byEntity.LocalEyePos.Y - 0.25f, 0); Vec3d aheadPos = lpos.AheadCopy(0.25f, byEntity.SidedPos.Pitch, byEntity.SidedPos.Yaw); (ends[0].Pinned ? ends[1] : ends[0]).PinTo(byEntity, aheadPos.ToVec3f()); ItemStack stack = new ItemStack(entity.World.GetItem(new AssetLocation("rope"))); stack.Attributes.SetInt("clothId", sys.ClothId); if (!byEntity.TryGiveItemStack(stack)) { entity.World.SpawnItemEntity(stack, byEntity.Pos.XYZ); } } }
public override void OnInteract(EntityAgent byEntity, ItemSlot itemslot, Vec3d hitPosition, EnumInteractMode mode) { EntityPlayer entityPlayer = byEntity as EntityPlayer; if (entityPlayer != null) { IPlayer byPlayer = World.PlayerByUid(entityPlayer.PlayerUID); if (byPlayer != null) { if (!CanCollect(byPlayer)) { IServerPlayer sp = byPlayer as IServerPlayer; if (sp != null) { sp.SendIngameError("", Lang.Get("game:ingameerror-not-corpse-owner")); } } else { if (Api.Side == EnumAppSide.Server) { if (Inventory == null || Inventory.Count == 0) { string format = "{0} at {1} is empty and will be removed immediately, id {3}"; string msg = string.Format(format, GetName(), SidedPos.XYZ.RelativePos(Api), byPlayer.PlayerName, EntityId); Core.ModLogger.Notification(msg); Die(); } else if (SecondsPassed > Config.Current.CorpseCollectionTime.Value) { Collect(byPlayer); } } LastInteractPassedMs = World.ElapsedMilliseconds; return; } } } base.OnInteract(byEntity, itemslot, hitPosition, mode); }