コード例 #1
0
 public override void OnHeldAttackStop(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
 {
 }
コード例 #2
0
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.Attributes.GetInt("aimingCancel") == 1)
            {
                return;
            }

            byEntity.Attributes.SetInt("aiming", 0);
            byEntity.StopAnimation("aim");

            if (secondsUsed < 0.35f)
            {
                return;
            }

            float  damage   = 1;
            string rockType = slot.Itemstack.Collectible.FirstCodePart(1);

            ItemStack stack = slot.TakeOut(1);

            slot.MarkDirty();

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }
            byEntity.World.PlaySoundAt(new AssetLocation("sounds/player/throw"), byEntity, byPlayer, false, 8);

            EntityProperties type   = byEntity.World.GetEntityType(new AssetLocation("thrownstone"));
            Entity           entity = byEntity.World.ClassRegistry.CreateEntity(type);

            ((EntityThrownStone)entity).FiredBy         = byEntity;
            ((EntityThrownStone)entity).Damage          = damage;
            ((EntityThrownStone)entity).ProjectileStack = stack;


            int?texIndex = type.Attributes?["texturealternateMapping"]?[rockType].AsInt(0);

            entity.WatchedAttributes.SetInt("textureIndex", texIndex == null ? 0 : (int)texIndex);

            float  acc      = (1 - byEntity.Attributes.GetFloat("aimingAccuracy", 0));
            double rndpitch = byEntity.WatchedAttributes.GetDouble("aimingRandPitch", 1) * acc * 0.75;
            double rndyaw   = byEntity.WatchedAttributes.GetDouble("aimingRandYaw", 1) * acc * 0.75;

            Vec3d pos      = byEntity.ServerPos.XYZ.Add(0, byEntity.EyeHeight - 0.2, 0);
            Vec3d aheadPos = pos.AheadCopy(1, byEntity.ServerPos.Pitch + rndpitch, byEntity.ServerPos.Yaw + rndyaw);
            Vec3d velocity = (aheadPos - pos) * 0.5;

            entity.ServerPos.SetPos(
                byEntity.ServerPos.BehindCopy(0.21).XYZ.Add(0, byEntity.EyeHeight - 0.2, 0)
                );

            //.Ahead(0.25, 0, byEntity.ServerPos.Yaw + GameMath.PIHALF)

            entity.ServerPos.Motion.Set(velocity);

            entity.Pos.SetFrom(entity.ServerPos);
            entity.World = byEntity.World;
            ((EntityThrownStone)entity).SetRotation();

            byEntity.World.SpawnEntity(entity);
            byEntity.StartAnimation("throw");

            //byEntity.GetBehavior<EntityBehaviorHunger>()?.ConsumeSaturation(2f);
        }
コード例 #3
0
 public override bool OnHeldInteractCancel(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason)
 {
     byEntity.Attributes.SetInt("aiming", 0);
     byEntity.StopAnimation("aim");
     return(true);
 }
コード例 #4
0
 public AiTaskWander(EntityAgent entity) : base(entity)
 {
 }
コード例 #5
0
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (byEntity.Attributes.GetInt("aimingCancel") == 1)
            {
                return;
            }
            byEntity.Attributes.SetInt("aiming", 0);
            byEntity.AnimManager.StopAnimation("slingaimbalearic");

            byEntity.World.RegisterCallback((dt) => slot.Itemstack?.Attributes.SetInt("renderVariant", 2), 250);
            byEntity.World.RegisterCallback((dt) =>
            {
                if (byEntity.World is IClientWorldAccessor)
                {
                    slot.Itemstack?.TempAttributes.RemoveAttribute("renderVariant");
                }
                slot.Itemstack?.Attributes.SetInt("renderVariant", 0);
            }, 450);



            (byEntity as EntityPlayer)?.Player?.InventoryManager.BroadcastHotbarSlot();

            if (secondsUsed < 0.35f)
            {
                return;
            }

            ItemSlot arrowSlot = GetNextMunition(byEntity);

            if (arrowSlot == null)
            {
                return;
            }

            float damage = 0;

            // Sling damage
            if (slot.Itemstack.Collectible.Attributes != null)
            {
                damage += slot.Itemstack.Collectible.Attributes["damage"].AsFloat(0);
            }

            // Stone damage
            if (arrowSlot.Itemstack.Collectible.Attributes != null)
            {
                damage += arrowSlot.Itemstack.Collectible.Attributes["damage"].AsFloat(0);
            }

            ItemStack stack = arrowSlot.TakeOut(1);

            arrowSlot.MarkDirty();

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }
            byEntity.World.PlaySoundAt(new AssetLocation("sounds/tool/sling1"), byEntity, byPlayer, false, 8, 0.25f);


            EntityProperties type   = byEntity.World.GetEntityType(new AssetLocation("thrownstone-" + stack.Collectible.Variant["rock"]));
            Entity           entity = byEntity.World.ClassRegistry.CreateEntity(type);

            ((EntityThrownStone)entity).FiredBy         = byEntity;
            ((EntityThrownStone)entity).Damage          = damage;
            ((EntityThrownStone)entity).ProjectileStack = stack;


            float  acc      = Math.Max(0.001f, (1 - byEntity.Attributes.GetFloat("aimingAccuracy", 0)));
            double rndpitch = byEntity.WatchedAttributes.GetDouble("aimingRandPitch", 1) * acc * 0.75;
            double rndyaw   = byEntity.WatchedAttributes.GetDouble("aimingRandYaw", 1) * acc * 0.75;

            Vec3d pos      = byEntity.ServerPos.XYZ.Add(0, byEntity.LocalEyePos.Y, 0);
            Vec3d aheadPos = pos.AheadCopy(1, byEntity.SidedPos.Pitch + rndpitch, byEntity.SidedPos.Yaw + rndyaw);
            Vec3d velocity = (aheadPos - pos) * byEntity.Stats.GetBlended("bowDrawingStrength") * 0.75f;


            entity.ServerPos.SetPos(byEntity.SidedPos.BehindCopy(0.21).XYZ.Add(0, byEntity.LocalEyePos.Y, 0));
            entity.ServerPos.Motion.Set(velocity);



            entity.Pos.SetFrom(entity.ServerPos);
            entity.World = byEntity.World;

            byEntity.World.SpawnEntity(entity);

            slot.Itemstack.Collectible.DamageItem(byEntity.World, byEntity, slot);

            byEntity.AnimManager.StartAnimation("slingthrowbalearic");

            byEntity.World.RegisterCallback((dt) => byEntity.AnimManager.StopAnimation("slingthrowbalearic"), 400);
        }
コード例 #6
0
        public AiTaskSeekFoodAndEat(EntityAgent entity) : base(entity)
        {
            porregistry = entity.Api.ModLoader.GetModSystem <POIRegistry>();

            entity.WatchedAttributes.SetBool("doesEat", true);
        }
コード例 #7
0
 public AiTaskIdle(EntityAgent entity) : base(entity)
 {
 }
コード例 #8
0
ファイル: EntityBehavior.cs プロジェクト: anegostudios/vsapi
 public virtual void DidAttack(DamageSource source, EntityAgent targetEntity, ref EnumHandling handled)
 {
     handled = EnumHandling.PassThrough;
 }
コード例 #9
0
 public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
 {
     base.OnHeldInteractStart(itemslot, byEntity, blockSel, entitySel, firstEvent, ref handHandling);
 }
コード例 #10
0
        public override string GetContentNutritionFacts(IWorldAccessor world, ItemSlot inSlotorFirstSlot, ItemStack[] contentStacks, EntityAgent forEntity, bool mulWithStacksize = false, float nutritionMul = 1, float healthMul = 1)
        {
            UnspoilContents(world, contentStacks);

            return(base.GetContentNutritionFacts(world, inSlotorFirstSlot, contentStacks, forEntity, mulWithStacksize, nutritionMul, healthMul));
        }
コード例 #11
0
ファイル: EntityBehavior.cs プロジェクト: anegostudios/vsapi
 /// <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)
 {
 }
コード例 #12
0
 public AiTaskForm(EntityAgent entity) : base(entity)
 {
 }
コード例 #13
0
        public GuiDialogConfirmPurchase(ICoreClientAPI capi, EntityAgent buyerEntity, EntityAgent auctioneerEntity, Auction auction) : base(capi)
        {
            this.buyerEntity  = buyerEntity;
            this.traderEntity = auctioneerEntity;
            this.auction      = auction;

            auctionSys = capi.ModLoader.GetModSystem <ModSystemAuction>();
            Init();
        }
コード例 #14
0
 public AiTaskBellAlarm(EntityAgent entity) : base(entity)
 {
     sapi = entity.World.Api as ICoreServerAPI;
 }
コード例 #15
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (finishedKnocking || blockSel == null)
            {
                return(true);
            }

            if (byEntity.World is IClientWorldAccessor)
            {
                // byEntity.Api.Logger.Debug("" + blockSel.);

                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                float knockStep = secondsUsed % knockDuration;

                tf.Origin.Set(0, -1, 0);
                tf.Rotation.Z = Math.Min(30, knockStep * speed);

                if (knockStep > knockDuration - 0.1f)
                {
                    // First knock determines which block you're selecting to knock
                    if (numberOfKnocks == 0)
                    {
                        selectedBlock = blockSel.Position;
                    }
                    else     // On subsequent knocks, check to see if the block being knocked is the same. If not, reset the knocking process

                    {
                        if (selectedBlock != blockSel.Position)
                        {
                            selectedBlock  = blockSel.Position;
                            numberOfKnocks = 1;
                        }
                    }

                    // Executes once per knock
                    if (!reachedKnock)
                    {
                        IPlayer byPlayer = (byEntity as EntityPlayer).Player;

                        reachedKnock    = true;
                        numberOfKnocks += 1;

                        // Once max knocks is reached, execute this code
                        if (numberOfKnocks >= maxKnocks)
                        {
                            ICoreClientAPI clientAPI = (ICoreClientAPI)byEntity.Api;

                            numberOfKnocks   = 0;
                            finishedKnocking = true;
                            tf.Rotation.Z    = 0;
                            byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/chop1"), byPlayer, byPlayer);
                            SpawnParticle(10, byEntity);

                            BlockPos plrpos     = byPlayer.Entity.Pos.AsBlockPos;
                            float    oreDensity = 0;

                            int    maxDistance = 32;
                            string oreType     = GetOreType(slot.Itemstack.Item.Code.GetName());

                            // Searches the radius around the selected block, returning an 'intensity' dependent on how many blocks it finds and how close they are
                            api.World.BlockAccessor.WalkBlocks(
                                plrpos.AddCopy(-maxDistance, -maxDistance, -maxDistance),
                                plrpos.AddCopy(maxDistance, maxDistance, maxDistance),
                                (block, pos) => oreDensity += (block.BlockMaterial.Equals(EnumBlockMaterial.Ore) && block.LastCodePart(1).ToString().Contains(oreType)) ? 1 / pos.DistanceTo(blockSel.Position) : 0
                                );

                            // (block, pos) => oreDensity += (!block.Code.Path.Contains("quartz") && block.BlockMaterial.Equals(EnumBlockMaterial.Ore)) ? 1 / pos.DistanceTo(blockSel.Position) : 0

                            /* Look into this method later, could be more efficient
                             * api.World.BlockAccessor.SearchBlocks(
                             *  plrpos.AddCopy(-64, -64, -64),
                             *  plrpos.AddCopy(64, 64, 64),
                             *  (block, pos) => quantityLogs += !block.BlockMaterial.Equals(EnumBlockMaterial.Ore) ? 0 : 1
                             * );
                             */

                            // Reduced the durability of the Knocker by 1
                            int durability = slot.Itemstack.Attributes.GetInt("durability", 5000);
                            durability -= 1;
                            slot.Itemstack.Attributes.SetInt("durability", durability);

                            float correctOreDensity = CorrectOreDensity(oreType, oreDensity);

                            clientAPI.ShowChatMessage(slot.Itemstack.GetName());
                            clientAPI.ShowChatMessage("Ore Intensity: " + GetIntensityLevel(correctOreDensity) + " (" + correctOreDensity + ")");
                        }
                        else
                        {
                            byEntity.World.PlaySoundAt(new AssetLocation("sounds/block/chop3"), byPlayer, byPlayer);
                            SpawnParticle(1, byEntity);
                        }
                    }
                }
                else
                {
                    reachedKnock = false;
                }

                byEntity.Controls.UsingHeldItemTransformAfter = tf;
            }
            return(true);
        }
コード例 #16
0
 public override void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handling)
 {
 }
コード例 #17
0
 public AiTaskGetOutOfWater(EntityAgent entity) : base(entity)
 {
 }
コード例 #18
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null)
            {
                return;
            }

            ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink;

            if (be != null)
            {
                handHandling = EnumHandHandling.PreventDefault;
            }

            if (be != null && be.CanReceiveAny)
            {
                KeyValuePair <ItemStack, int> contents = GetContents(byEntity.World, slot.Itemstack);

                if (contents.Key == null)
                {
                    string emptiedCode = Attributes["emptiedBlockCode"].AsString();

                    slot.Itemstack = new ItemStack(byEntity.World.GetBlock(AssetLocation.Create(emptiedCode, Code.Domain)));
                    slot.MarkDirty();
                    handHandling = EnumHandHandling.PreventDefault;
                    return;
                }


                if (HasSolidifed(slot.Itemstack, contents.Key, byEntity.World))
                {
                    handHandling = EnumHandHandling.NotHandled;
                    return;
                }

                if (contents.Value <= 0)
                {
                    return;
                }
                if (!be.CanReceive(contents.Key))
                {
                    return;
                }
                be.BeginFill(blockSel.HitPosition);

                byEntity.World.RegisterCallback((world, pos, dt) =>
                {
                    if (byEntity.Controls.HandUse == EnumHandInteract.HeldItemInteract)
                    {
                        IPlayer byPlayer = null;
                        if (byEntity is EntityPlayer)
                        {
                            byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
                        }

                        world.PlaySoundAt(new AssetLocation("sounds/pourmetal"), byEntity, byPlayer);
                    }
                }, blockSel.Position, 666);

                handHandling = EnumHandHandling.PreventDefault;
            }
        }
コード例 #19
0
        public override void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }


            if (byEntity.Controls.Sneak && blockSel != null)
            {
                IWorldAccessor world         = byEntity.World;
                Block          knappingBlock = world.GetBlock(new AssetLocation("knappingsurface"));
                if (knappingBlock == null)
                {
                    return;
                }

                Block block = world.BlockAccessor.GetBlock(blockSel.Position);
                if (!block.CanAttachBlockAt(byEntity.World.BlockAccessor, knappingBlock, blockSel.Position, BlockFacing.UP))
                {
                    if (api.Side == EnumAppSide.Client)
                    {
                        (api as ICoreClientAPI).TriggerIngameError(this, "cantplace", Lang.Get("Cannot place a knapping surface here"));
                    }
                    return;
                }

                BlockPos pos = blockSel.Position.AddCopy(blockSel.Face);
                if (!world.BlockAccessor.GetBlock(pos).IsReplacableBy(knappingBlock))
                {
                    return;
                }

                BlockSelection placeSel = blockSel.Clone();
                placeSel.Position  = pos;
                placeSel.DidOffset = true;
                string useless = "";

                if (!knappingBlock.TryPlaceBlock(world, byPlayer, slot.Itemstack, placeSel, ref useless))
                {
                    if (api.Side == EnumAppSide.Client)
                    {
                        bool selfBlocked   = false;
                        bool entityBlocked = world.GetIntersectingEntities(pos, knappingBlock.GetCollisionBoxes(world.BlockAccessor, pos), e => { selfBlocked = e == byEntity; return(!(e is EntityItem)); }).Length != 0;

                        string err =
                            entityBlocked ?
                            (selfBlocked ? Lang.Get("Cannot place a knapping surface here, too close to you") : Lang.Get("Cannot place a knapping surface here, to close to another player or creature.")) :
                            Lang.Get("Cannot place a knapping surface here")
                        ;

                        (api as ICoreClientAPI).TriggerIngameError(this, "cantplace", err);
                    }

                    return;
                }

                world.BlockAccessor.TriggerNeighbourBlockUpdate(pos);

                if (knappingBlock.Sounds != null)
                {
                    world.PlaySoundAt(knappingBlock.Sounds.Place, pos.X, pos.Y, pos.Z);
                }

                BlockEntityKnappingSurface bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityKnappingSurface;
                if (bec != null)
                {
                    bec.BaseMaterial           = slot.Itemstack.Clone();
                    bec.BaseMaterial.StackSize = 1;

                    if (byEntity.World is IClientWorldAccessor)
                    {
                        bec.OpenDialog(world as IClientWorldAccessor, pos, slot.Itemstack);
                    }
                }

                slot.TakeOut(1);

                handling = EnumHandHandling.PreventDefaultAction;
                return;
            }

            base.OnHeldInteractStart(slot, byEntity, blockSel, entitySel, firstEvent, ref handling);
        }
コード例 #20
0
        public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (blockSel == null)
            {
                return(false);
            }

            ILiquidMetalSink be = byEntity.World.BlockAccessor.GetBlockEntity(blockSel.Position) as ILiquidMetalSink;

            if (be == null)
            {
                return(false);
            }

            if (!be.CanReceiveAny)
            {
                return(false);
            }
            KeyValuePair <ItemStack, int> contents = GetContents(byEntity.World, slot.Itemstack);

            if (!be.CanReceive(contents.Key))
            {
                return(false);
            }

            float speed = 1.5f;
            float temp  = GetTemperature(byEntity.World, slot.Itemstack);

            if (byEntity.World is IClientWorldAccessor)
            {
                ModelTransform tf = new ModelTransform();
                tf.EnsureDefaultValues();

                tf.Origin.Set(0.5f, 0.2f, 0.5f);
                tf.Translation.Set(0, 0, -Math.Min(0.25f, speed * secondsUsed / 4));
                tf.Scale      = 1f + Math.Min(0.25f, speed * secondsUsed / 4);
                tf.Rotation.X = Math.Max(-110, -secondsUsed * 90 * speed);
                byEntity.Controls.UsingHeldItemTransformBefore = tf;
            }

            IPlayer byPlayer = null;

            if (byEntity is EntityPlayer)
            {
                byPlayer = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
            }


            if (secondsUsed > 1 / speed)
            {
                if ((int)(30 * secondsUsed) % 3 == 1)
                {
                    Vec3d pos =
                        byEntity.Pos.XYZ
                        .Ahead(0.1f, byEntity.Pos.Pitch, byEntity.Pos.Yaw)
                        .Ahead(1.0f, byEntity.Pos.Pitch, byEntity.Pos.Yaw - GameMath.PIHALF)
                    ;
                    pos.Y += byEntity.LocalEyePos.Y - 0.4f;

                    smokePouring.MinPos = pos.AddCopy(-0.15, -0.15, -0.15);

                    Vec3d blockpos = blockSel.Position.ToVec3d().Add(0.5, 0.2, 0.5);

                    bigMetalSparks.MinQuantity = Math.Max(0.2f, 1 - (secondsUsed - 1) / 4);

                    if ((int)(30 * secondsUsed) % 7 == 1)
                    {
                        bigMetalSparks.MinPos = pos;
                        bigMetalSparks.MinVelocity.Set(-2, -1, -2);
                        bigMetalSparks.AddVelocity.Set(4, 1, 4);
                        byEntity.World.SpawnParticles(bigMetalSparks, byPlayer);

                        byEntity.World.SpawnParticles(smokePouring, byPlayer);
                    }

                    float     y2       = 0;
                    Block     block    = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);
                    Cuboidf[] collboxs = block.GetCollisionBoxes(byEntity.World.BlockAccessor, blockSel.Position);
                    for (int i = 0; collboxs != null && i < collboxs.Length; i++)
                    {
                        y2 = Math.Max(y2, collboxs[i].Y2);
                    }

                    // Metal Spark on the mold
                    bigMetalSparks.MinVelocity.Set(-2, 1, -2);
                    bigMetalSparks.AddVelocity.Set(4, 5, 4);
                    bigMetalSparks.MinPos = blockpos.AddCopy(-0.25, y2 - 2 / 16f, -0.25);
                    bigMetalSparks.AddPos.Set(0.5, 0, 0.5);
                    bigMetalSparks.VertexFlags = (byte)GameMath.Clamp((int)temp - 770, 48, 128);
                    byEntity.World.SpawnParticles(bigMetalSparks, byPlayer);

                    // Smoke on the mold
                    byEntity.World.SpawnParticles(
                        Math.Max(1, 12 - (secondsUsed - 1) * 6),
                        ColorUtil.ToRgba(50, 220, 220, 220),
                        blockpos.AddCopy(-0.5, y2 - 2 / 16f, -0.5),
                        blockpos.Add(0.5, y2 - 2 / 16f + 0.15, 0.5),
                        new Vec3f(-0.5f, 0f, -0.5f),
                        new Vec3f(0.5f, 0f, 0.5f),
                        1.5f,
                        -0.05f,
                        0.75f,
                        EnumParticleModel.Quad,
                        byPlayer
                        );
                }

                int transferedAmount = Math.Min(2, contents.Value);


                be.ReceiveLiquidMetal(contents.Key, ref transferedAmount, temp);

                int newAmount = Math.Max(0, contents.Value - (2 - transferedAmount));
                slot.Itemstack.Attributes.SetInt("units", newAmount);


                if (newAmount <= 0 && byEntity.World is IServerWorldAccessor)
                {
                    string emptiedCode = Attributes["emptiedBlockCode"].AsString();
                    slot.Itemstack = new ItemStack(byEntity.World.GetBlock(AssetLocation.Create(emptiedCode, Code.Domain)));
                    slot.MarkDirty();
                    // Since we change the item stack we have to call this ourselves
                    OnHeldInteractStop(secondsUsed, slot, byEntity, blockSel, entitySel);
                    return(false);
                }

                return(true);
            }

            return(true);
        }
コード例 #21
0
ファイル: Auction.cs プロジェクト: anegostudios/vssurvivalmod
        public void PlaceAuction(ItemSlot slot, int quantity, int price, double durationHours, int depositCost, EntityAgent sellerEntity, Entity auctioneerEntity, out string failureCode)
        {
            if (slot.StackSize < quantity)
            {
                failureCode = "notenoughitems";
                return;
            }

            if (GetAuctionsFrom((sellerEntity as EntityPlayer).Player).Count > 30)
            {
                failureCode = "toomanyauctions";
                return;
            }

            int monehs = InventoryTrader.GetPlayerAssets(sellerEntity);

            if (monehs < GetDepositCost(slot) * depositCost)
            {
                failureCode = "notenoughgears";
                return;
            }

            failureCode = null;
            InventoryTrader.DeductFromEntity(sapi, sellerEntity, depositCost);
            (auctioneerEntity as EntityTrader).Inventory?.GiveToTrader(depositCost);


            long id = ++auctionsData.nextAuctionId;

            string sellerName = sellerEntity.GetBehavior <EntityBehaviorNameTag>()?.DisplayName;

            if (sellerName == null)
            {
                sellerName = sellerEntity.Properties.Code.ToShortString();
            }


            float  debt;
            string uid = (sellerEntity as EntityPlayer)?.PlayerUID ?? "";

            auctionsData.DebtToTraderByPlayer.TryGetValue(uid, out debt);

            float traderCutGears = price * SalesCutRate + debt;

            auctionsData.DebtToTraderByPlayer[uid] = traderCutGears - (int)traderCutGears;


            var auction = new Auction()
            {
                AuctionId              = id,
                ExpireTotalHours       = sapi.World.Calendar.TotalHours + durationHours,
                ItemStack              = slot.TakeOut(quantity),
                PostedTotalHours       = sapi.World.Calendar.TotalHours,
                Price                  = price,
                TraderCut              = (int)traderCutGears,
                SellerName             = sellerName,
                SellerUid              = (sellerEntity as EntityPlayer)?.PlayerUID,
                SellerEntityId         = sellerEntity.EntityId,
                SrcAuctioneerEntityPos = auctioneerEntity.Pos.XYZ,
                SrcAuctioneerEntityId  = auctioneerEntity.EntityId
            };

            auctions.Add(id, auction);
            slot.MarkDirty();

            sendAuctions(new Auction[] { auction }, null);
        }
コード例 #22
0
 public AiTaskStayCloseToEntity(EntityAgent entity) : base(entity)
 {
 }
コード例 #23
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling)
        {
            if (blockSel == null || byEntity?.World == null || !byEntity.Controls.Sneak)
            {
                return;
            }

            IWorldAccessor world        = byEntity.World;
            Block          firepitBlock = world.GetBlock(new AssetLocation("firepit-construct1"));

            if (firepitBlock == null)
            {
                return;
            }


            BlockPos onPos = blockSel.DidOffset ? blockSel.Position : blockSel.Position.AddCopy(blockSel.Face);

            IPlayer byPlayer = byEntity.World.PlayerByUid((byEntity as EntityPlayer)?.PlayerUID);

            if (!byEntity.World.Claims.TryAccess(byPlayer, onPos, EnumBlockAccessFlags.BuildOrBreak))
            {
                return;
            }



            Block block      = world.BlockAccessor.GetBlock(onPos.DownCopy());
            Block aimedBlock = world.BlockAccessor.GetBlock(blockSel.Position);

            if (aimedBlock is BlockGroundStorage)
            {
                if (!(aimedBlock is BlockPitkiln))
                {
                    BlockPitkiln blockpk = world.GetBlock(new AssetLocation("pitkiln")) as BlockPitkiln;
                    if (blockpk.TryCreateKiln(world, byPlayer, blockSel.Position))
                    {
                        handHandling = EnumHandHandling.PreventDefault;
                    }
                }
            }
            else
            {
                string useless = "";

                if (!block.CanAttachBlockAt(byEntity.World.BlockAccessor, firepitBlock, onPos.DownCopy(), BlockFacing.UP))
                {
                    return;
                }
                if (!firepitBlock.CanPlaceBlock(world, byPlayer, new BlockSelection()
                {
                    Position = onPos, Face = BlockFacing.UP
                }, ref useless))
                {
                    return;
                }

                world.BlockAccessor.SetBlock(firepitBlock.BlockId, onPos);

                if (firepitBlock.Sounds != null)
                {
                    world.PlaySoundAt(firepitBlock.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z, byPlayer);
                }

                itemslot.Itemstack.StackSize--;
                handHandling = EnumHandHandling.PreventDefaultAction;
            }
        }
コード例 #24
0
 public AiTaskButterflyChase(EntityAgent entity) : base(entity)
 {
 }
コード例 #25
0
        public override void OnHeldInteractStart(ItemSlot itemslot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handling)
        {
            bool knappable          = itemslot.Itemstack.Collectible.Attributes != null && itemslot.Itemstack.Collectible.Attributes["knappable"].AsBool(false);
            bool haveKnappableStone = false;

            IPlayer byPlayer = (byEntity as EntityPlayer)?.Player;

            if (byEntity.Controls.Sneak && blockSel != null)
            {
                Block block = byEntity.World.BlockAccessor.GetBlock(blockSel.Position);
                haveKnappableStone =
                    block.Code.Path.StartsWith("loosestones") &&
                    block.FirstCodePart(1).Equals(itemslot.Itemstack.Collectible.FirstCodePart(1))
                ;
            }

            if (haveKnappableStone)
            {
                if (!knappable)
                {
                    if (byEntity.World.Side == EnumAppSide.Client)
                    {
                        (this.api as ICoreClientAPI).TriggerIngameError(this, "toosoft", Lang.Get("This type of stone is too soft to be used for knapping."));
                    }
                    return;
                }

                if (!byEntity.World.Claims.TryAccess(byPlayer, blockSel.Position, EnumBlockAccessFlags.Use))
                {
                    itemslot.MarkDirty();
                    return;
                }

                IWorldAccessor world         = byEntity.World;
                Block          knappingBlock = world.GetBlock(new AssetLocation("knappingsurface"));
                if (knappingBlock == null)
                {
                    return;
                }

                string failCode = "";

                BlockPos pos = blockSel.Position;
                knappingBlock.IsSuitablePosition(world, pos, ref failCode);

                if (failCode == "entityintersecting")
                {
                    bool selfBlocked   = false;
                    bool entityBlocked = world.GetIntersectingEntities(pos, knappingBlock.GetCollisionBoxes(world.BlockAccessor, pos), e => { selfBlocked = e == byEntity; return(!(e is EntityItem)); }).Length != 0;

                    string err =
                        entityBlocked ?
                        (selfBlocked ? Lang.Get("Cannot place a knapping surface here, too close to you") : Lang.Get("Cannot place a knapping surface here, to close to another player or creature.")) :
                        Lang.Get("Cannot place a knapping surface here")
                    ;

                    (api as ICoreClientAPI).TriggerIngameError(this, "cantplace", err);

                    return;
                }

                world.BlockAccessor.SetBlock(knappingBlock.BlockId, pos);
                world.BlockAccessor.TriggerNeighbourBlockUpdate(blockSel.Position);

                if (knappingBlock.Sounds != null)
                {
                    world.PlaySoundAt(knappingBlock.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);
                }

                BlockEntityKnappingSurface bec = world.BlockAccessor.GetBlockEntity(pos) as BlockEntityKnappingSurface;
                if (bec != null)
                {
                    bec.BaseMaterial           = itemslot.Itemstack.Clone();
                    bec.BaseMaterial.StackSize = 1;

                    if (byEntity.World is IClientWorldAccessor)
                    {
                        bec.OpenDialog(world as IClientWorldAccessor, pos, itemslot.Itemstack);
                    }
                }
                //itemslot.Take(1);

                handling = EnumHandHandling.PreventDefault;
                byEntity.Attributes.SetInt("aimingCancel", 1);
                return;
            }

            if (blockSel != null && byEntity?.World != null && byEntity.Controls.Sneak)
            {
                IWorldAccessor world = byEntity.World;
                Block          block = world.GetBlock(CodeWithPath("loosestones-" + LastCodePart()));
                if (block == null)
                {
                    block = world.GetBlock(CodeWithPath("loosestones-" + LastCodePart(1) + "-" + LastCodePart(0)));
                }
                if (block == null)
                {
                    return;
                }

                if (!world.BlockAccessor.GetBlock(blockSel.Position).SideSolid[BlockFacing.UP.Index])
                {
                    return;
                }

                BlockPos       targetpos = blockSel.Position.AddCopy(blockSel.Face);
                BlockSelection placeSel  = blockSel.Clone();
                placeSel.Position  = targetpos;
                placeSel.DidOffset = true;
                string useless = "";

                if (!block.TryPlaceBlock(world, byPlayer, itemslot.Itemstack, placeSel, ref useless))
                {
                    return;
                }

                world.BlockAccessor.TriggerNeighbourBlockUpdate(blockSel.Position);

                if (block.Sounds != null)
                {
                    world.PlaySoundAt(block.Sounds.Place, blockSel.Position.X, blockSel.Position.Y, blockSel.Position.Z);
                }

                itemslot.Itemstack.StackSize--;

                handling = EnumHandHandling.PreventDefault;
                byEntity.Attributes.SetInt("aimingCancel", 1);
                return;
            }

            if (byEntity.Controls.Sneak)
            {
                return;
            }


            // Not ideal to code the aiming controls this way. Needs an elegant solution - maybe an event bus?
            byEntity.Attributes.SetInt("aiming", 1);
            byEntity.Attributes.SetInt("aimingCancel", 0);
            byEntity.StartAnimation("aim");

            handling = EnumHandHandling.PreventDefault;
        }
コード例 #26
0
 public AiTaskButterflyChase(EntityAgent entity, EntityButterfly chaseTarget) : base(entity)
 {
     chaseTime    = (float)entity.World.Rand.NextDouble() * 7 + 6;
     targetEntity = chaseTarget;
     targetPos.Set(targetEntity.ServerPos.X, targetEntity.ServerPos.Y, targetEntity.ServerPos.Z);
 }
コード例 #27
0
 public override bool OnHeldAttackStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel)
 {
     return(false);
 }
コード例 #28
0
 public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
 {
     numberOfKnocks   = 0;
     finishedKnocking = false;
     base.OnHeldInteractStop(secondsUsed, slot, byEntity, blockSel, entitySel);
 }
コード例 #29
0
 public override bool OnHeldAttackCancel(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel, EnumItemUseCancelReason cancelReason)
 {
     return(false);
 }
コード例 #30
0
 public AiTaskMeleeAttackTargetingEntity(EntityAgent entity) : base(entity)
 {
 }