Beispiel #1
0
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            ItemStack content = GetContent(slot.Itemstack);

            if (secondsUsed > 1.45f && byEntity.World.Side == EnumAppSide.Server && content != null)
            {
                if (essencesDic.TryGetValue("duration", out duration))
                {
                    if (!essencesDic.ContainsKey("health"))
                    {
                        TempEffect potionEffect = new TempEffect();
                        potionEffect.tempEntityStats((byEntity as EntityPlayer), essencesDic);
                    }
                    else
                    {
                        TempEffect potionEffect = new TempEffect();
                        potionEffect.tempTickEntityStats((byEntity as EntityPlayer), essencesDic, tickSec, essencesDic["health"]);
                    }
                    if (byEntity is EntityPlayer)
                    {
                        IServerPlayer sPlayer = (byEntity.World.PlayerByUid((byEntity as EntityPlayer).PlayerUID) as IServerPlayer);
                        if (essencesDic.ContainsKey("recall"))
                        {
                            if (api.Side.IsServer())
                            {
                                FuzzyEntityPos spawn = sPlayer.GetSpawnPosition(false);
                                byEntity.TeleportTo(spawn);
                            }
                        }
                        sPlayer.SendMessage(GlobalConstants.InfoLogChatGroup, "You feel the effects of the " + content.GetName(), EnumChatType.Notification);
                    }
                    IPlayer player = null;
                    if (byEntity is EntityPlayer)
                    {
                        player = byEntity.World.PlayerByUid(((EntityPlayer)byEntity).PlayerUID);
                    }
                    if (slot.StackSize > 1)
                    {
                        ItemStack newStack = slot.Itemstack.Clone();
                        newStack.StackSize = slot.StackSize - 1;
                        ItemStack newContent = GetContent(newStack);
                        api.World.SpawnItemEntity(newStack, byEntity.Pos.XYZ);
                        slot.TakeOut(slot.StackSize - 1);
                    }
                    splitStackAndPerformAction(byEntity, slot, (stack) => TryTakeLiquid(stack, 0.25f)?.StackSize ?? 0);
                    slot.MarkDirty();

                    EntityPlayer entityPlayer = byEntity as EntityPlayer;
                    if (entityPlayer == null)
                    {
                        return;
                    }
                    entityPlayer.Player.InventoryManager.BroadcastHotbarSlot();
                }
            }
            base.OnHeldInteractStop(secondsUsed, slot, byEntity, blockSel, entitySel);
        }
        /* This override is to add the behavior to the player of when they die they also reset all of their potion effects */
        public override void OnEntityDeath(DamageSource damageSourceForDeath)
        {
            IServerPlayer player = GetIServerPlayer();

            TempEffect tempEffect = new TempEffect();

            tempEffect.reset((player.Entity as EntityPlayer), false);

            base.OnEntityDeath(damageSourceForDeath);
        }
Beispiel #3
0
 /* This override is to add the PotionFixBehavior to the player and to reset all of the potion stats to default */
 public override void StartServerSide(ICoreServerAPI api)
 {
     this.sapi = api;
     api.Event.PlayerNowPlaying += (IServerPlayer iServerPlayer) =>
     {
         if (iServerPlayer.Entity is EntityPlayer)
         {
             Entity entity = iServerPlayer.Entity;
             entity.AddBehavior(new PotionFixBehavior(entity, config));
             //api.Logger.Debug("[Potion] Adding PotionFixBehavior to spawned EntityPlayer");
             TempEffect   tempEffect = new TempEffect();
             EntityPlayer player     = (iServerPlayer.Entity as EntityPlayer);
             tempEffect.reset(player, false);
             //api.Logger.Debug("potion player ready");
         }
     };
     base.StartServerSide(api);
 }
Beispiel #4
0
        public override void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel)
        {
            if (secondsUsed > 1.45f && byEntity.World.Side == EnumAppSide.Server)
            {
                if (tickSec == 0)
                {
                    TempEffect potionEffect = new TempEffect();
                    potionEffect.tempEntityStats((byEntity as EntityPlayer), essencesDic);
                }
                else
                {
                    TempEffect potionEffect = new TempEffect();
                    potionEffect.tempTickEntityStats((byEntity as EntityPlayer), essencesDic, tickSec, health);
                }
                if (byEntity is EntityPlayer)
                {
                    IServerPlayer player = (byEntity.World.PlayerByUid((byEntity as EntityPlayer).PlayerUID) as IServerPlayer);
                    if (essencesDic.ContainsKey("recall"))
                    {
                        if (api.Side.IsServer())
                        {
                            FuzzyEntityPos spawn = player.GetSpawnPosition(false);
                            byEntity.TeleportTo(spawn);
                        }
                        player.SendMessage(GlobalConstants.InfoLogChatGroup, "You feel the effects of the " + slot.Itemstack.GetName(), EnumChatType.Notification);
                    }
                    else
                    {
                        player.SendMessage(GlobalConstants.InfoLogChatGroup, "You feel the effects of the " + slot.Itemstack.GetName(), EnumChatType.Notification);
                    }
                }

                slot.TakeOut(1);
                slot.MarkDirty();
            }
        }