예제 #1
0
        public object SpellsTake(LookupKey lookupKey, [FromBody] SpellInfo spell)
        {
            if (lookupKey.IsInvalid)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.BadRequest, lookupKey.IsIdInvalid ? @"Invalid player id." : @"Invalid player name."
                           ));
            }

            if (SpellBase.Get(spell.SpellId) == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"Invalid spell id."));
            }

            var(client, player) = Player.Fetch(lookupKey);
            if (player == null)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.NotFound,
                           lookupKey.HasId
                        ? $@"No player with id '{lookupKey.Id}'."
                        : $@"No player with name '{lookupKey.Name}'."
                           ));
            }

            if (player.TryForgetSpell(new Spell(spell.SpellId), true))
            {
                return(spell);
            }

            return(Request.CreateErrorResponse(
                       HttpStatusCode.InternalServerError, $@"Failed to remove player spell with id '{spell.SpellId}'."
                       ));
        }
예제 #2
0
        public DoT(Entity attacker, Guid spellId, Entity target)
        {
            SpellBase = SpellBase.Get(spellId);

            Attacker = attacker;
            Target   = target;

            if (SpellBase == null || SpellBase.Combat.HotDotInterval < 1)
            {
                return;
            }

            // Does target have a cleanse buff? If so, do not allow this DoT when spell is unfriendly.
            if (!SpellBase.Combat.Friendly)
            {
                foreach (var status in Target.CachedStatuses)
                {
                    if (status.Type == StatusTypes.Cleanse)
                    {
                        return;
                    }
                }
            }


            mInterval = Globals.Timing.Milliseconds + SpellBase.Combat.HotDotInterval;
            Count     = SpellBase.Combat.Duration / SpellBase.Combat.HotDotInterval - 1;
            target.DoT.TryAdd(Id, this);
            target.CachedDots = target.DoT.Values.ToArray();

            //Subtract 1 since the first tick always occurs when the spell is cast.
        }
예제 #3
0
 private void cmbSpell_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cmbSpell.SelectedIndex > 0)
     {
         mEditorItem.Spell = SpellBase.Get(SpellBase.IdFromList(cmbSpell.SelectedIndex - 1));
     }
     else
     {
         mEditorItem.Spell = null;
     }
 }
예제 #4
0
        //SpellCastPacket
        private static void HandlePacket(SpellCastPacket packet)
        {
            var entityId = packet.EntityId;
            var spellId  = packet.SpellId;

            if (SpellBase.Get(spellId) != null && Globals.Entities.ContainsKey(entityId))
            {
                Globals.Entities[entityId].CastTime  = Globals.System.GetTimeMs() + SpellBase.Get(spellId).CastDuration;
                Globals.Entities[entityId].SpellCast = spellId;
            }
        }
예제 #5
0
        private void lstSpells_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (mChangingName)
            {
                return;
            }

            if (lstSpells.SelectedNode == null || lstSpells.SelectedNode.Tag == null)
            {
                return;
            }

            mEditorItem = SpellBase.Get((Guid)lstSpells.SelectedNode.Tag);
            UpdateEditor();
        }
예제 #6
0
        public DoT(Entity attacker, Guid spellId, Entity target)
        {
            SpellBase = SpellBase.Get(spellId);

            Attacker = attacker;
            Target   = target;

            if (SpellBase == null || SpellBase.Combat.HotDotInterval < 1)
            {
                return;
            }

            mInterval = Globals.Timing.TimeMs + SpellBase.Combat.HotDotInterval;
            Count     = SpellBase.Combat.Duration / SpellBase.Combat.HotDotInterval - 1;
            target.DoT.Add(this);

            //Subtract 1 since the first tick always occurs when the spell is cast.
        }
        public object SpellsTeach(LookupKey lookupKey, [FromBody] SpellInfo spell)
        {
            if (lookupKey.IsInvalid)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.BadRequest, lookupKey.IsIdInvalid ? @"Invalid player id." : @"Invalid player name."
                           ));
            }

            if (SpellBase.Get(spell.SpellId) == null)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, @"Invalid spell id."));
            }

            var(client, player) = Player.Fetch(lookupKey);
            if (player == null)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.NotFound,
                           lookupKey.HasId
                        ? $@"No player with id '{lookupKey.Id}'."
                        : $@"No player with name '{lookupKey.Name}'."
                           ));
            }

            if (player.TryTeachSpell(new Spell(spell.SpellId), true))
            {
                using (var context = DbInterface.CreatePlayerContext(false))
                {
                    context.Update(player);
                    context.SaveChanges();
                }

                return(spell);
            }

            return(Request.CreateErrorResponse(
                       HttpStatusCode.InternalServerError,
                       $@"Failed to teach player spell with id '{spell.SpellId}'. They might already know it!"
                       ));
        }
예제 #8
0
        private void TryCastSpells()
        {
            // Check if NPC is stunned/sleeping
            if (IsStunnedOrSleeping)
            {
                return;
            }

            //Check if NPC is casting a spell
            if (CastTime > Globals.Timing.TimeMs)
            {
                return; //can't move while casting
            }

            if (CastFreq >= Globals.Timing.TimeMs)
            {
                return;
            }

            // Check if the NPC is able to cast spells
            if (IsUnableToCastSpells)
            {
                return;
            }

            if (Base.Spells == null || Base.Spells.Count <= 0)
            {
                return;
            }

            // Pick a random spell
            var spellIndex = Randomization.Next(0, Spells.Count);
            var spellId    = Base.Spells[spellIndex];
            var spellBase  = SpellBase.Get(spellId);

            if (spellBase == null)
            {
                return;
            }

            if (spellBase.Combat == null)
            {
                Log.Warn($"Combat data missing for {spellBase.Id}.");
            }

            var range          = spellBase.Combat?.CastRange ?? 0;
            var targetType     = spellBase.Combat?.TargetType ?? SpellTargetTypes.Single;
            var projectileBase = spellBase.Combat?.Projectile;

            if (spellBase.SpellType == SpellTypes.CombatSpell &&
                targetType == SpellTargetTypes.Projectile &&
                projectileBase != null &&
                InRangeOf(Target, projectileBase.Range))
            {
                range = projectileBase.Range;
                var dirToEnemy = DirToEnemy(Target);
                if (dirToEnemy != Dir)
                {
                    if (LastRandomMove >= Globals.Timing.TimeMs)
                    {
                        return;
                    }

                    //Face the target -- next frame fire -- then go on with life
                    ChangeDir(dirToEnemy); // Gotta get dir to enemy
                    LastRandomMove = Globals.Timing.TimeMs + Randomization.Next(1000, 3000);

                    return;
                }
            }

            if (spellBase.VitalCost == null)
            {
                return;
            }

            if (spellBase.VitalCost[(int)Vitals.Mana] > GetVital(Vitals.Mana))
            {
                return;
            }

            if (spellBase.VitalCost[(int)Vitals.Health] > GetVital(Vitals.Health))
            {
                return;
            }

            var spell = Spells[spellIndex];

            if (spell == null)
            {
                return;
            }

            if (SpellCooldowns.ContainsKey(spell.SpellId) && SpellCooldowns[spell.SpellId] >= Globals.Timing.RealTimeMs)
            {
                return;
            }

            if (!InRangeOf(Target, range))
            {
                // ReSharper disable once SwitchStatementMissingSomeCases
                switch (targetType)
                {
                case SpellTargetTypes.Self:
                case SpellTargetTypes.AoE:
                    return;
                }
            }

            CastTime = Globals.Timing.TimeMs + spellBase.CastDuration;

            if (spellBase.VitalCost[(int)Vitals.Mana] > 0)
            {
                SubVital(Vitals.Mana, spellBase.VitalCost[(int)Vitals.Mana]);
            }
            else
            {
                AddVital(Vitals.Mana, -spellBase.VitalCost[(int)Vitals.Mana]);
            }

            if (spellBase.VitalCost[(int)Vitals.Health] > 0)
            {
                SubVital(Vitals.Health, spellBase.VitalCost[(int)Vitals.Health]);
            }
            else
            {
                AddVital(Vitals.Health, -spellBase.VitalCost[(int)Vitals.Health]);
            }

            if ((spellBase.Combat?.Friendly ?? false) && spellBase.SpellType != SpellTypes.WarpTo)
            {
                CastTarget = this;
            }
            else
            {
                CastTarget = Target;
            }

            switch (Base.SpellFrequency)
            {
            case 0:
                CastFreq = Globals.Timing.TimeMs + 30000;

                break;

            case 1:
                CastFreq = Globals.Timing.TimeMs + 15000;

                break;

            case 2:
                CastFreq = Globals.Timing.TimeMs + 8000;

                break;

            case 3:
                CastFreq = Globals.Timing.TimeMs + 4000;

                break;

            case 4:
                CastFreq = Globals.Timing.TimeMs + 2000;

                break;
            }

            SpellCastSlot = spellIndex;

            if (spellBase.CastAnimationId != Guid.Empty)
            {
                PacketSender.SendAnimationToProximity(spellBase.CastAnimationId, 1, Id, MapId, 0, 0, (sbyte)Dir);

                //Target Type 1 will be global entity
            }

            PacketSender.SendEntityVitals(this);
            PacketSender.SendEntityCastTime(this, spellId);
        }
예제 #9
0
        public void Update()
        {
            if (Globals.Me == null)
            {
                return;
            }

            //See if Label Should be changed
            if (mHotKey != Controls.ActiveControls.ControlMapping[Control.Hotkey1 + mYindex].Key1)
            {
                KeyLabel.SetText(
                    Strings.Keys.keydict[
                        Enum.GetName(
                            typeof(Keys), Controls.ActiveControls.ControlMapping[Control.Hotkey1 + mYindex].Key1
                            )
                        .ToLower()]
                    );

                mHotKey = Controls.ActiveControls.ControlMapping[Control.Hotkey1 + mYindex].Key1;
            }

            var slot          = Globals.Me.Hotbar[mYindex];
            var updateDisplay =
                mCurrentId != slot.ItemOrSpellId ||
                mTexLoaded ==
                false; //Update display if the hotbar item changes or we dont have a texture for the current item

            if (mCurrentId != slot.ItemOrSpellId)
            {
                mCurrentItem  = null;
                mCurrentSpell = null;
                var itm = ItemBase.Get(slot.ItemOrSpellId);
                var spl = SpellBase.Get(slot.ItemOrSpellId);
                if (itm != null)
                {
                    mCurrentItem = itm;
                }

                if (spl != null)
                {
                    mCurrentSpell = spl;
                }

                mCurrentId = slot.ItemOrSpellId;
            }

            mSpellBookItem      = null;
            mInventoryItem      = null;
            mInventoryItemIndex = -1;

            if (mCurrentItem != null)
            {
                var itmIndex = Globals.Me.FindHotbarItem(slot);
                if (itmIndex > -1)
                {
                    mInventoryItemIndex = itmIndex;
                    mInventoryItem      = Globals.Me.Inventory[itmIndex];
                }
            }
            else if (mCurrentSpell != null)
            {
                var splIndex = Globals.Me.FindHotbarSpell(slot);
                if (splIndex > -1)
                {
                    mSpellBookItem = Globals.Me.Spells[splIndex];
                }
            }

            if (mCurrentItem != null) //When it's an item
            {
                //We don't have it, and the icon isn't faded
                if (mInventoryItem == null && !mIsFaded)
                {
                    updateDisplay = true;
                }

                //We have it, and the equip icon doesn't match equipped status
                if (mInventoryItem != null && Globals.Me.IsEquipped(mInventoryItemIndex) != mIsEquipped)
                {
                    updateDisplay = true;
                }

                //We have it, and it's on cd
                if (mInventoryItem != null && Globals.Me.ItemOnCd(mInventoryItemIndex))
                {
                    updateDisplay = true;
                }

                //We have it, and it's on cd, and the fade is incorrect
                if (mInventoryItem != null && Globals.Me.ItemOnCd(mInventoryItemIndex) != mIsFaded)
                {
                    updateDisplay = true;
                }
            }

            if (mCurrentSpell != null) //When it's a spell
            {
                //We don't know it, and the icon isn't faded!
                if (mSpellBookItem == null && !mIsFaded)
                {
                    updateDisplay = true;
                }

                //Spell on cd
                if (mSpellBookItem != null &&
                    Globals.Me.GetSpellCooldown(mSpellBookItem.SpellId) > Globals.System.GetTimeMs())
                {
                    updateDisplay = true;
                }

                //Spell on cd and the fade is incorrect
                if (mSpellBookItem != null &&
                    Globals.Me.GetSpellCooldown(mSpellBookItem.SpellId) > Globals.System.GetTimeMs() != mIsFaded)
                {
                    updateDisplay = true;
                }
            }

            if (updateDisplay) //Item on cd and fade is incorrect
            {
                if (mCurrentItem != null)
                {
                    mCooldownLabel.IsHidden = true;
                    mContentPanel.Show();
                    mContentPanel.Texture = Globals.ContentManager.GetTexture(
                        GameContentManager.TextureType.Item, mCurrentItem.Icon
                        );

                    if (mInventoryItemIndex > -1)
                    {
                        EquipPanel.IsHidden = !Globals.Me.IsEquipped(mInventoryItemIndex);
                        EquipLabel.IsHidden = !Globals.Me.IsEquipped(mInventoryItemIndex);
                        mIsFaded            = Globals.Me.ItemOnCd(mInventoryItemIndex);
                        if (mIsFaded)
                        {
                            mCooldownLabel.IsHidden = false;
                            var secondsRemaining = (float)Globals.Me.ItemCdRemainder(mInventoryItemIndex) / 1000f;
                            if (secondsRemaining > 10f)
                            {
                                mCooldownLabel.Text =
                                    Strings.Inventory.cooldown.ToString(secondsRemaining.ToString("N0"));
                            }
                            else
                            {
                                mCooldownLabel.Text = Strings.Inventory.cooldown.ToString(
                                    secondsRemaining.ToString("N1").Replace(".", Strings.Numbers.dec)
                                    );
                            }
                        }

                        mIsEquipped = Globals.Me.IsEquipped(mInventoryItemIndex);
                    }
                    else
                    {
                        EquipPanel.IsHidden = true;
                        EquipLabel.IsHidden = true;
                        mIsEquipped         = false;
                        mIsFaded            = true;
                    }

                    mTexLoaded = true;
                }
                else if (mCurrentSpell != null)
                {
                    mContentPanel.Show();
                    mContentPanel.Texture = Globals.ContentManager.GetTexture(
                        GameContentManager.TextureType.Spell, mCurrentSpell.Icon
                        );

                    EquipPanel.IsHidden     = true;
                    EquipLabel.IsHidden     = true;
                    mCooldownLabel.IsHidden = true;
                    if (mSpellBookItem != null)
                    {
                        mIsFaded = Globals.Me.GetSpellCooldown(mSpellBookItem.SpellId) > Globals.System.GetTimeMs();
                        if (mIsFaded)
                        {
                            mCooldownLabel.IsHidden = false;
                            var secondsRemaining =
                                (float)(Globals.Me.GetSpellCooldown(mSpellBookItem.SpellId) -
                                        Globals.System.GetTimeMs()) /
                                1000f;

                            if (secondsRemaining > 10f)
                            {
                                mCooldownLabel.Text = Strings.Spells.cooldown.ToString(secondsRemaining.ToString("N0"));
                            }
                            else
                            {
                                mCooldownLabel.Text = Strings.Spells.cooldown.ToString(
                                    secondsRemaining.ToString("N1").Replace(".", Strings.Numbers.dec)
                                    );
                            }
                        }
                    }
                    else
                    {
                        mIsFaded = true;
                    }

                    mTexLoaded  = true;
                    mIsEquipped = false;
                }
                else
                {
                    mContentPanel.Hide();
                    mTexLoaded              = true;
                    mIsEquipped             = false;
                    EquipPanel.IsHidden     = true;
                    EquipLabel.IsHidden     = true;
                    mCooldownLabel.IsHidden = true;
                }

                if (mIsFaded)
                {
                    if (mCurrentSpell != null)
                    {
                        mContentPanel.RenderColor = new Color(100, 255, 255, 255);
                    }

                    if (mCurrentItem != null)
                    {
                        mContentPanel.RenderColor = new Color(100, mCurrentItem.Color.R, mCurrentItem.Color.G, mCurrentItem.Color.B);
                    }
                }
                else
                {
                    if (mCurrentSpell != null)
                    {
                        mContentPanel.RenderColor = Color.White;
                    }

                    if (mCurrentItem != null)
                    {
                        mContentPanel.RenderColor = mCurrentItem.Color;
                    }
                }
            }

            if (mCurrentItem != null || mCurrentSpell != null)
            {
                if (!IsDragging)
                {
                    if (mMouseOver)
                    {
                        if (!Globals.InputManager.MouseButtonDown(GameInput.MouseButtons.Left))
                        {
                            mCanDrag = true;
                            mMouseX  = -1;
                            mMouseY  = -1;
                            if (Globals.System.GetTimeMs() < mClickTime)
                            {
                                Activate();
                                mClickTime = 0;
                            }
                        }
                        else
                        {
                            if (mCanDrag && Draggable.Active == null)
                            {
                                if (mMouseX == -1 || mMouseY == -1)
                                {
                                    mMouseX = InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X;
                                    mMouseY = InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y;
                                }
                                else
                                {
                                    var xdiff = mMouseX -
                                                (InputHandler.MousePosition.X -
                                                 Pnl.LocalPosToCanvas(new Point(0, 0)).X);

                                    var ydiff = mMouseY -
                                                (InputHandler.MousePosition.Y -
                                                 Pnl.LocalPosToCanvas(new Point(0, 0)).Y);

                                    if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5)
                                    {
                                        IsDragging = true;
                                        mDragIcon  = new Draggable(
                                            Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseX,
                                            Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseY, mContentPanel.Texture
                                            );

                                        //SOMETHING SHOULD BE RENDERED HERE, RIGHT?
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (mDragIcon.Update())
                    {
                        mContentPanel.IsHidden = false;

                        //Drug the item and now we stopped
                        IsDragging = false;
                        var dragRect = new FloatRect(
                            mDragIcon.X - sItemXPadding / 2, mDragIcon.Y - sItemYPadding / 2, sItemXPadding / 2 + 32,
                            sItemYPadding / 2 + 32
                            );

                        float bestIntersect      = 0;
                        var   bestIntersectIndex = -1;

                        if (Interface.GameUi.Hotbar.RenderBounds().IntersectsWith(dragRect))
                        {
                            for (var i = 0; i < Options.MaxHotbar; i++)
                            {
                                if (Interface.GameUi.Hotbar.Items[i].RenderBounds().IntersectsWith(dragRect))
                                {
                                    if (FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect)
                                        .Width *
                                        FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect)
                                        .Height >
                                        bestIntersect)
                                    {
                                        bestIntersect =
                                            FloatRect.Intersect(
                                                Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect
                                                )
                                            .Width *
                                            FloatRect.Intersect(
                                                Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect
                                                )
                                            .Height;

                                        bestIntersectIndex = i;
                                    }
                                }
                            }

                            if (bestIntersectIndex > -1 && bestIntersectIndex != mYindex)
                            {
                                Globals.Me.HotbarSwap(mYindex, (byte)bestIntersectIndex);
                            }
                        }

                        mDragIcon.Dispose();
                    }
                    else
                    {
                        mContentPanel.IsHidden = true;
                    }
                }
            }
        }
예제 #10
0
        //GameObjectPacket
        private static void HandlePacket(GameObjectPacket packet)
        {
            var id      = packet.Id;
            var deleted = packet.Deleted;
            var json    = "";

            if (!packet.Deleted)
            {
                json = packet.Data;
            }

            switch (packet.Type)
            {
            case GameObjectType.Animation:
                if (deleted)
                {
                    var anim = AnimationBase.Get(id);
                    anim.Delete();
                }
                else
                {
                    var anim = new AnimationBase(id);
                    anim.Load(json);
                    try
                    {
                        AnimationBase.Lookup.Set(id, anim);
                    }
                    catch (Exception exception)
                    {
                        Log.Error($"Another mystery NPE. [Lookup={AnimationBase.Lookup}]");
                        if (exception.InnerException != null)
                        {
                            Log.Error(exception.InnerException);
                        }

                        Log.Error(exception);
                        Log.Error($"{nameof(id)}={id},{nameof(anim)}={anim}");

                        throw;
                    }
                }

                break;

            case GameObjectType.Class:
                if (deleted)
                {
                    var cls = ClassBase.Get(id);
                    cls.Delete();
                }
                else
                {
                    var cls = new ClassBase(id);
                    cls.Load(json);
                    ClassBase.Lookup.Set(id, cls);
                }

                break;

            case GameObjectType.Item:
                if (deleted)
                {
                    var itm = ItemBase.Get(id);
                    itm.Delete();
                }
                else
                {
                    var itm = new ItemBase(id);
                    itm.Load(json);
                    ItemBase.Lookup.Set(id, itm);
                }

                break;

            case GameObjectType.Npc:
                if (deleted)
                {
                    var npc = NpcBase.Get(id);
                    npc.Delete();
                }
                else
                {
                    var npc = new NpcBase(id);
                    npc.Load(json);
                    NpcBase.Lookup.Set(id, npc);
                }

                break;

            case GameObjectType.Projectile:
                if (deleted)
                {
                    var proj = ProjectileBase.Get(id);
                    proj.Delete();
                }
                else
                {
                    var proj = new ProjectileBase(id);
                    proj.Load(json);
                    ProjectileBase.Lookup.Set(id, proj);
                }

                break;

            case GameObjectType.Quest:
                if (deleted)
                {
                    var qst = QuestBase.Get(id);
                    qst.Delete();
                }
                else
                {
                    var qst = new QuestBase(id);
                    qst.Load(json);
                    foreach (var tsk in qst.Tasks)
                    {
                        qst.OriginalTaskEventIds.Add(tsk.Id, tsk.CompletionEventId);
                    }

                    QuestBase.Lookup.Set(id, qst);
                }

                break;

            case GameObjectType.Resource:
                if (deleted)
                {
                    var res = ResourceBase.Get(id);
                    res.Delete();
                }
                else
                {
                    var res = new ResourceBase(id);
                    res.Load(json);
                    ResourceBase.Lookup.Set(id, res);
                }

                break;

            case GameObjectType.Shop:
                if (deleted)
                {
                    var shp = ShopBase.Get(id);
                    shp.Delete();
                }
                else
                {
                    var shp = new ShopBase(id);
                    shp.Load(json);
                    ShopBase.Lookup.Set(id, shp);
                }

                break;

            case GameObjectType.Spell:
                if (deleted)
                {
                    var spl = SpellBase.Get(id);
                    spl.Delete();
                }
                else
                {
                    var spl = new SpellBase(id);
                    spl.Load(json);
                    SpellBase.Lookup.Set(id, spl);
                }

                break;

            case GameObjectType.CraftTables:
                if (deleted)
                {
                    var cft = CraftingTableBase.Get(id);
                    cft.Delete();
                }
                else
                {
                    var cft = new CraftingTableBase(id);
                    cft.Load(json);
                    CraftingTableBase.Lookup.Set(id, cft);
                }

                break;

            case GameObjectType.Crafts:
                if (deleted)
                {
                    var cft = CraftBase.Get(id);
                    cft.Delete();
                }
                else
                {
                    var cft = new CraftBase(id);
                    cft.Load(json);
                    CraftBase.Lookup.Set(id, cft);
                }

                break;

            case GameObjectType.Map:
                //Handled in a different packet
                break;

            case GameObjectType.Event:
                var wasCommon = false;
                if (deleted)
                {
                    var evt = EventBase.Get(id);
                    wasCommon = evt.CommonEvent;
                    evt.Delete();
                }
                else
                {
                    var evt = new EventBase(id);
                    evt.Load(json);
                    wasCommon = evt.CommonEvent;
                    EventBase.Lookup.Set(id, evt);
                }

                if (!wasCommon)
                {
                    return;
                }

                break;

            case GameObjectType.PlayerVariable:
                if (deleted)
                {
                    var pvar = PlayerVariableBase.Get(id);
                    pvar.Delete();
                }
                else
                {
                    var pvar = new PlayerVariableBase(id);
                    pvar.Load(json);
                    PlayerVariableBase.Lookup.Set(id, pvar);
                }

                break;

            case GameObjectType.ServerVariable:
                if (deleted)
                {
                    var svar = ServerVariableBase.Get(id);
                    svar.Delete();
                }
                else
                {
                    var svar = new ServerVariableBase(id);
                    svar.Load(json);
                    ServerVariableBase.Lookup.Set(id, svar);
                }

                break;

            case GameObjectType.Tileset:
                var obj = new TilesetBase(id);
                obj.Load(json);
                TilesetBase.Lookup.Set(id, obj);
                if (Globals.HasGameData && !packet.AnotherFollowing)
                {
                    GameContentManager.LoadTilesets();
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            GameObjectUpdatedDelegate?.Invoke(packet.Type);
        }
        public void Update()
        {
            if (mStatus != null)
            {
                var remaining        = mStatus.RemainingMs();
                var spell            = SpellBase.Get(mStatus.SpellId);
                var secondsRemaining = (float)remaining / 1000f;
                if (secondsRemaining > 10f)
                {
                    mDurationLabel.Text =
                        Strings.EntityBox.cooldown.ToString(((float)remaining / 1000f).ToString("N0"));
                }
                else
                {
                    mDurationLabel.Text = Strings.EntityBox.cooldown.ToString(
                        ((float)remaining / 1000f).ToString("N1").Replace(".", Strings.Numbers.dec)
                        );
                }

                if ((mTexLoaded != "" && spell == null ||
                     spell != null && mTexLoaded != spell.Icon ||
                     mCurrentSpellId != mStatus.SpellId) &&
                    remaining > 0)
                {
                    Container.Show();
                    if (spell != null)
                    {
                        var spellTex = Globals.ContentManager.GetTexture(
                            GameContentManager.TextureType.Spell, spell.Icon
                            );

                        if (spellTex != null)
                        {
                            Pnl.Texture  = spellTex;
                            Pnl.IsHidden = false;
                        }
                        else
                        {
                            if (Pnl.Texture != null)
                            {
                                Pnl.Texture = null;
                            }
                        }

                        mTexLoaded      = spell.Icon;
                        mCurrentSpellId = mStatus.SpellId;
                    }
                    else
                    {
                        if (Pnl.Texture != null)
                        {
                            Pnl.Texture = null;
                        }

                        mTexLoaded = "";
                    }
                }
                else if (remaining <= 0)
                {
                    if (Pnl.Texture != null)
                    {
                        Pnl.Texture = null;
                    }

                    Container.Hide();
                    mTexLoaded = "";
                }
            }
        }
예제 #12
0
 private void cmbTeachSpell_SelectedIndexChanged(object sender, EventArgs e)
 {
     mEditorItem.Spell = SpellBase.Get(SpellBase.IdFromList(cmbTeachSpell.SelectedIndex - 1));
 }
예제 #13
0
        public void InitEditor()
        {
            var selectedId  = Guid.Empty;
            var folderNodes = new Dictionary <string, TreeNode>();

            if (lstSpells.SelectedNode != null && lstSpells.SelectedNode.Tag != null)
            {
                selectedId = (Guid)lstSpells.SelectedNode.Tag;
            }

            lstSpells.Nodes.Clear();

            cmbScalingStat.Items.Clear();
            for (var i = 0; i < Options.MaxStats; i++)
            {
                cmbScalingStat.Items.Add(Globals.GetStatName(i));
            }

            //Collect folders
            var mFolders = new List <string>();

            foreach (var itm in SpellBase.Lookup)
            {
                if (!string.IsNullOrEmpty(((SpellBase)itm.Value).Folder) &&
                    !mFolders.Contains(((SpellBase)itm.Value).Folder))
                {
                    mFolders.Add(((SpellBase)itm.Value).Folder);
                    if (!mKnownFolders.Contains(((SpellBase)itm.Value).Folder))
                    {
                        mKnownFolders.Add(((SpellBase)itm.Value).Folder);
                    }
                }
            }

            mFolders.Sort();
            mKnownFolders.Sort();
            cmbFolder.Items.Clear();
            cmbFolder.Items.Add("");
            cmbFolder.Items.AddRange(mKnownFolders.ToArray());

            lstSpells.Sorted = !btnChronological.Checked;

            if (!btnChronological.Checked && !CustomSearch())
            {
                foreach (var folder in mFolders)
                {
                    var node = lstSpells.Nodes.Add(folder);
                    node.ImageIndex         = 0;
                    node.SelectedImageIndex = 0;
                    folderNodes.Add(folder, node);
                }
            }

            foreach (var itm in SpellBase.ItemPairs)
            {
                var node = new TreeNode(itm.Value);
                node.Tag                = itm.Key;
                node.ImageIndex         = 1;
                node.SelectedImageIndex = 1;

                var folder = SpellBase.Get(itm.Key).Folder;
                if (!string.IsNullOrEmpty(folder) && !btnChronological.Checked && !CustomSearch())
                {
                    var folderNode = folderNodes[folder];
                    folderNode.Nodes.Add(node);
                    if (itm.Key == selectedId)
                    {
                        folderNode.Expand();
                    }
                }
                else
                {
                    lstSpells.Nodes.Add(node);
                }

                if (CustomSearch())
                {
                    if (!node.Text.ToLower().Contains(txtSearch.Text.ToLower()))
                    {
                        node.Remove();
                    }
                }

                if (itm.Key == selectedId)
                {
                    lstSpells.SelectedNode = node;
                }
            }

            var selectedNode = lstSpells.SelectedNode;

            if (!btnChronological.Checked)
            {
                lstSpells.Sort();
            }

            lstSpells.SelectedNode = selectedNode;
            foreach (var node in mExpandedFolders)
            {
                if (folderNodes.ContainsKey(node))
                {
                    folderNodes[node].Expand();
                }
            }
        }
예제 #14
0
        public SpellDescWindow(Guid spellId, int x, int y, bool centerHorizontally = false)
        {
            var spell = SpellBase.Get(spellId);

            if (spell == null)
            {
                return;
            }

            mDescWindow = new ImagePanel(Interface.GameUi.GameCanvas, "SpellDescWindowExpanded");

            var icon = new ImagePanel(mDescWindow, "SpellIcon");

            var spellName = new Label(mDescWindow, "SpellName");

            spellName.Text = spell.Name;

            var spellType = new Label(mDescWindow, "SpellType");

            spellType.Text = Strings.SpellDesc.spelltypes[(int)spell.SpellType];

            var spellDesc     = new RichLabel(mDescWindow, "SpellDesc");
            var spellStats    = new RichLabel(mDescWindow, "SpellStats");
            var spellDescText = new Label(mDescWindow, "SpellDescText");

            spellDescText.Font = spellDescText.Parent.Skin.DefaultFont;
            var spellStatsText = new Label(mDescWindow, "SpellStatsText");

            spellStatsText.Font     = spellStatsText.Parent.Skin.DefaultFont;
            spellDescText.IsHidden  = true;
            spellStatsText.IsHidden = true;

            //Load this up now so we know what color to make the text when filling out the desc
            mDescWindow.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
            if (spell.Description.Length > 0)
            {
                spellDesc.AddText(
                    Strings.SpellDesc.desc.ToString(spell.Description), spellDesc.RenderColor,
                    spellDescText.CurAlignments.Count > 0 ? spellDescText.CurAlignments[0] : Alignments.Left,
                    spellDescText.Font
                    );

                spellDesc.AddLineBreak();
                spellDesc.AddLineBreak();
            }

            if (spell.SpellType == (int)SpellTypes.CombatSpell)
            {
                if (spell.Combat.TargetType == SpellTargetTypes.Projectile)
                {
                    var proj = ProjectileBase.Get(spell.Combat.ProjectileId);
                    spellType.Text = Strings.SpellDesc.targettypes[(int)spell.Combat.TargetType]
                                     .ToString(proj?.Range ?? 0, spell.Combat.HitRadius);
                }
                else
                {
                    spellType.Text = Strings.SpellDesc.targettypes[(int)spell.Combat.TargetType]
                                     .ToString(spell.Combat.CastRange, spell.Combat.HitRadius);
                }
            }

            if (spell.SpellType == (int)SpellTypes.CombatSpell &&
                (spell.Combat.TargetType == SpellTargetTypes.AoE ||
                 spell.Combat.TargetType == SpellTargetTypes.Single) &&
                spell.Combat.HitRadius > 0)
            {
                spellStats.AddText(
                    Strings.SpellDesc.radius.ToString(spell.Combat.HitRadius), spellStats.RenderColor,
                    spellStatsText.CurAlignments.Count > 0 ? spellStatsText.CurAlignments[0] : Alignments.Left,
                    spellStatsText.Font
                    );

                spellStats.AddLineBreak();
                spellStats.AddLineBreak();
            }

            if (spell.CastDuration > 0)
            {
                var castDuration = (float)spell.CastDuration / 1000f;
                spellStats.AddText(
                    Strings.SpellDesc.casttime.ToString(castDuration), spellStats.RenderColor,
                    spellStatsText.CurAlignments.Count > 0 ? spellStatsText.CurAlignments[0] : Alignments.Left,
                    spellStatsText.Font
                    );

                spellStats.AddLineBreak();
                if (spell.CooldownDuration <= 0)
                {
                    spellStats.AddLineBreak();
                }
            }

            if (spell.CooldownDuration > 0)
            {
                var cdr = 1 - Globals.Me.GetCooldownReduction() / 100;
                var cd  = (float)(spell.CooldownDuration * cdr) / 1000f;
                spellStats.AddText(
                    Strings.SpellDesc.cooldowntime.ToString(cd), spellStats.RenderColor,
                    spellStatsText.CurAlignments.Count > 0 ? spellStatsText.CurAlignments[0] : Alignments.Left,
                    spellStatsText.Font
                    );

                spellStats.AddLineBreak();
                spellStats.AddLineBreak();
            }

            var requirements = spell.VitalCost[(int)Vitals.Health] > 0 || spell.VitalCost[(int)Vitals.Mana] > 0;

            if (requirements == true)
            {
                spellStats.AddText(
                    Strings.SpellDesc.prereqs, spellStats.RenderColor,
                    spellStatsText.CurAlignments.Count > 0 ? spellStatsText.CurAlignments[0] : Alignments.Left,
                    spellStatsText.Font
                    );

                spellStats.AddLineBreak();
                if (spell.VitalCost[(int)Vitals.Health] > 0)
                {
                    spellStats.AddText(
                        Strings.SpellDesc.vitalcosts[(int)Vitals.Health]
                        .ToString(spell.VitalCost[(int)Vitals.Health]), spellStats.RenderColor,
                        spellStatsText.CurAlignments.Count > 0 ? spellStatsText.CurAlignments[0] : Alignments.Left,
                        spellStatsText.Font
                        );

                    spellStats.AddLineBreak();
                }

                if (spell.VitalCost[(int)Vitals.Mana] > 0)
                {
                    spellStats.AddText(
                        Strings.SpellDesc.vitalcosts[(int)Vitals.Mana].ToString(spell.VitalCost[(int)Vitals.Mana]),
                        spellStats.RenderColor,
                        spellStatsText.CurAlignments.Count > 0 ? spellStatsText.CurAlignments[0] : Alignments.Left,
                        spellStatsText.Font
                        );

                    spellStats.AddLineBreak();
                }

                spellStats.AddLineBreak();
            }

            var stats = "";

            if (spell.SpellType == (int)SpellTypes.CombatSpell)
            {
                stats = Strings.SpellDesc.effects;
                spellStats.AddText(
                    stats, spellStats.RenderColor,
                    spellStatsText.CurAlignments.Count > 0 ? spellStatsText.CurAlignments[0] : Alignments.Left,
                    spellStatsText.Font
                    );

                spellStats.AddLineBreak();

                if (spell.Combat.Effect > 0)
                {
                    spellStats.AddText(
                        Strings.SpellDesc.effectlist[(int)spell.Combat.Effect], spellStats.RenderColor,
                        spellStatsText.CurAlignments.Count > 0 ? spellStatsText.CurAlignments[0] : Alignments.Left,
                        spellStatsText.Font
                        );

                    spellStats.AddLineBreak();
                }

                for (var i = 0; i < (int)Vitals.VitalCount; i++)
                {
                    var vitalDiff = spell.Combat.VitalDiff?[i] ?? 0;
                    if (vitalDiff == 0)
                    {
                        continue;
                    }

                    var vitalSymbol = vitalDiff < 0 ? Strings.SpellDesc.addsymbol : Strings.SpellDesc.removesymbol;
                    if (spell.Combat.Effect == StatusTypes.Shield)
                    {
                        stats = Strings.SpellDesc.shield.ToString(Math.Abs(vitalDiff));
                    }
                    else
                    {
                        stats = Strings.SpellDesc.vitals[i].ToString(vitalSymbol, Math.Abs(vitalDiff));
                    }

                    spellStats.AddText(
                        stats, spellStats.RenderColor,
                        spellStatsText.CurAlignments.Count > 0 ? spellStatsText.CurAlignments[0] : Alignments.Left,
                        spellStatsText.Font
                        );

                    spellStats.AddLineBreak();
                }

                if (spell.Combat.Duration > 0)
                {
                    for (var i = 0; i < (int)Stats.StatCount; i++)
                    {
                        if (spell.Combat.StatDiff[i] != 0)
                        {
                            spellStats.AddText(
                                Strings.SpellDesc.stats[i]
                                .ToString(
                                    (spell.Combat.StatDiff[i] > 0
                                            ? Strings.SpellDesc.addsymbol.ToString()
                                            : Strings.SpellDesc.removesymbol.ToString()) +
                                    Math.Abs(spell.Combat.StatDiff[i])
                                    ), spellStats.RenderColor,
                                spellStatsText.CurAlignments.Count > 0
                                    ? spellStatsText.CurAlignments[0]
                                    : Alignments.Left, spellStatsText.Font
                                );

                            spellStats.AddLineBreak();
                        }
                    }

                    var duration = (float)spell.Combat.Duration / 1000f;
                    spellStats.AddText(
                        Strings.SpellDesc.duration.ToString(duration), spellStats.RenderColor,
                        spellStatsText.CurAlignments.Count > 0 ? spellStatsText.CurAlignments[0] : Alignments.Left,
                        spellStatsText.Font
                        );

                    spellStats.AddLineBreak();
                }
            }

            spellStats.SizeToChildren(false, true);
            if (spellStats.Children.Count == 0)
            {
                mDescWindow.Name    = "SpellDescWindow";
                spellStats.Name     = "";
                spellStatsText.Name = "";
            }

            //Load Again for positioning purposes.
            mDescWindow.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
            spellDescText.IsHidden  = true;
            spellStatsText.IsHidden = true;
            icon.Texture            = Globals.ContentManager.GetTexture(GameContentManager.TextureType.Spell, spell.Icon);
            spellStats.SizeToChildren(false, true);
            if (centerHorizontally)
            {
                mDescWindow.MoveTo(x - mDescWindow.Width / 2, y + mDescWindow.Padding.Top);
            }
            else
            {
                mDescWindow.MoveTo(x - mDescWindow.Width - mDescWindow.Padding.Right, y + mDescWindow.Padding.Top);
            }
        }
예제 #15
0
        public void Update()
        {
            var spell = SpellBase.Get(Globals.Me.Spells[mYindex].SpellId);

            if (!IsDragging &&
                (mTexLoaded != "" && spell == null ||
                 spell != null && mTexLoaded != spell.Icon ||
                 mCurrentSpellId != Globals.Me.Spells[mYindex].SpellId ||
                 mIconCd !=
                 Globals.Me.GetSpellCooldown(Globals.Me.Spells[mYindex].SpellId) > Globals.System.GetTimeMs() ||
                 Globals.Me.GetSpellCooldown(Globals.Me.Spells[mYindex].SpellId) > Globals.System.GetTimeMs()))
            {
                mCooldownLabel.IsHidden = true;
                if (spell != null)
                {
                    var spellTex = Globals.ContentManager.GetTexture(GameContentManager.TextureType.Spell, spell.Icon);
                    if (spellTex != null)
                    {
                        Pnl.Texture = spellTex;
                        if (Globals.Me.GetSpellCooldown(Globals.Me.Spells[mYindex].SpellId) >
                            Globals.System.GetTimeMs())
                        {
                            Pnl.RenderColor = new Color(100, 255, 255, 255);
                        }
                        else
                        {
                            Pnl.RenderColor = new Color(255, 255, 255, 255);
                        }
                    }
                    else
                    {
                        if (Pnl.Texture != null)
                        {
                            Pnl.Texture = null;
                        }
                    }

                    mTexLoaded      = spell.Icon;
                    mCurrentSpellId = Globals.Me.Spells[mYindex].SpellId;
                    mIconCd         = Globals.Me.GetSpellCooldown(Globals.Me.Spells[mYindex].SpellId) >
                                      Globals.System.GetTimeMs();

                    if (mIconCd)
                    {
                        mCooldownLabel.IsHidden = false;
                        var secondsRemaining =
                            (float)(Globals.Me.GetSpellCooldown(Globals.Me.Spells[mYindex].SpellId) -
                                    Globals.System.GetTimeMs()) /
                            1000f;

                        if (secondsRemaining > 10f)
                        {
                            mCooldownLabel.Text = Strings.Spells.cooldown.ToString(secondsRemaining.ToString("N0"));
                        }
                        else
                        {
                            mCooldownLabel.Text = Strings.Spells.cooldown.ToString(
                                secondsRemaining.ToString("N1").Replace(".", Strings.Numbers.dec)
                                );
                        }
                    }
                }
                else
                {
                    if (Pnl.Texture != null)
                    {
                        Pnl.Texture = null;
                    }

                    mTexLoaded = "";
                }
            }

            if (!IsDragging)
            {
                if (mMouseOver)
                {
                    if (!Globals.InputManager.MouseButtonDown(GameInput.MouseButtons.Left))
                    {
                        mCanDrag = true;
                        mMouseX  = -1;
                        mMouseY  = -1;
                        if (Globals.System.GetTimeMs() < mClickTime)
                        {
                            Globals.Me.TryUseSpell(mYindex);
                            mClickTime = 0;
                        }
                    }
                    else
                    {
                        if (mCanDrag && Draggable.Active == null)
                        {
                            if (mMouseX == -1 || mMouseY == -1)
                            {
                                mMouseX = InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X;
                                mMouseY = InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y;
                            }
                            else
                            {
                                var xdiff = mMouseX -
                                            (InputHandler.MousePosition.X - Pnl.LocalPosToCanvas(new Point(0, 0)).X);

                                var ydiff = mMouseY -
                                            (InputHandler.MousePosition.Y - Pnl.LocalPosToCanvas(new Point(0, 0)).Y);

                                if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5)
                                {
                                    IsDragging = true;
                                    mDragIcon  = new Draggable(
                                        Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseX,
                                        Pnl.LocalPosToCanvas(new Point(0, 0)).X + mMouseY, Pnl.Texture
                                        );

                                    mTexLoaded = "";
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (mDragIcon.Update())
                {
                    //Drug the item and now we stopped
                    IsDragging = false;
                    var dragRect = new FloatRect(
                        mDragIcon.X - (Container.Padding.Left + Container.Padding.Right) / 2,
                        mDragIcon.Y - (Container.Padding.Top + Container.Padding.Bottom) / 2,
                        (Container.Padding.Left + Container.Padding.Right) / 2 + Pnl.Width,
                        (Container.Padding.Top + Container.Padding.Bottom) / 2 + Pnl.Height
                        );

                    float bestIntersect      = 0;
                    var   bestIntersectIndex = -1;

                    //So we picked up an item and then dropped it. Lets see where we dropped it to.
                    //Check spell first.
                    if (mSpellWindow.RenderBounds().IntersectsWith(dragRect))
                    {
                        for (var i = 0; i < Options.MaxInvItems; i++)
                        {
                            if (i < mSpellWindow.Items.Count &&
                                mSpellWindow.Items[i].RenderBounds().IntersectsWith(dragRect))
                            {
                                if (FloatRect.Intersect(mSpellWindow.Items[i].RenderBounds(), dragRect).Width *
                                    FloatRect.Intersect(mSpellWindow.Items[i].RenderBounds(), dragRect).Height >
                                    bestIntersect)
                                {
                                    bestIntersect =
                                        FloatRect.Intersect(mSpellWindow.Items[i].RenderBounds(), dragRect).Width *
                                        FloatRect.Intersect(mSpellWindow.Items[i].RenderBounds(), dragRect).Height;

                                    bestIntersectIndex = i;
                                }
                            }
                        }

                        if (bestIntersectIndex > -1)
                        {
                            if (mYindex != bestIntersectIndex)
                            {
                                //Try to swap....
                                PacketSender.SendSwapSpells(bestIntersectIndex, mYindex);
                                Globals.Me.SwapSpells(bestIntersectIndex, mYindex);
                            }
                        }
                    }
                    else if (Interface.GameUi.Hotbar.RenderBounds().IntersectsWith(dragRect))
                    {
                        for (var i = 0; i < Options.MaxHotbar; i++)
                        {
                            if (Interface.GameUi.Hotbar.Items[i].RenderBounds().IntersectsWith(dragRect))
                            {
                                if (FloatRect.Intersect(
                                        Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect
                                        )
                                    .Width *
                                    FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect)
                                    .Height >
                                    bestIntersect)
                                {
                                    bestIntersect =
                                        FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect)
                                        .Width *
                                        FloatRect.Intersect(Interface.GameUi.Hotbar.Items[i].RenderBounds(), dragRect)
                                        .Height;

                                    bestIntersectIndex = i;
                                }
                            }
                        }

                        if (bestIntersectIndex > -1)
                        {
                            Globals.Me.AddToHotbar((byte)bestIntersectIndex, 1, mYindex);
                        }
                    }

                    mDragIcon.Dispose();
                }
            }
        }
예제 #16
0
 private void AssignEditorItem(Guid id)
 {
     mEditorItem = SpellBase.Get(id);
     UpdateEditor();
 }