Beispiel #1
0
    public static void SendCastToArea(MapUnit unit, Spell.Spells spell, int x, int y)
    {
        Spell cspell = unit.GetSpell(spell);

        if (cspell == null)
        {
            return;
        }

        if (NetworkManager.IsClient)
        {
            ServerCommands.CastToArea careaCmd;
            careaCmd.TagFrom = unit.Tag;
            careaCmd.SpellID = (int)spell;
            careaCmd.TargetX = x;
            careaCmd.TargetY = y;
            ClientManager.SendCommand(careaCmd);
        }
        else
        {
            if (MapLogic.Instance.ConsolePlayer == unit.Player)
            {
                unit.SetState(new CastState(unit, cspell, x, y));
            }
        }
    }
Beispiel #2
0
    public Spell.Spells GetCastSpell()
    {
        Spell.Spells       splId = Spell.Spells.NoneSpell;
        Templates.TplSpell spl   = null;
        Spell itemSp             = GetOneTimeCast();

        if (itemSp != null)
        {
            splId = itemSp.SpellID;
            spl   = itemSp.Template;
        }
        else if (SpellbookVisible && Spellbook.Unit == SelectedObject && Spellbook.ActiveSpell != Spell.Spells.NoneSpell)
        {
            splId = Spellbook.ActiveSpell;
            spl   = TemplateLoader.GetSpellById((int)splId - 1);
        }

        if (spl != null &&
            (spl.IsAreaSpell ||
             (!spl.IsAreaSpell && HoveredObject != null && (HoveredObject.GetObjectType() == MapObjectType.Human || HoveredObject.GetObjectType() == MapObjectType.Monster))))
        {
            return(splId);
        }

        return(Spell.Spells.NoneSpell);
    }
Beispiel #3
0
    public static void SendCastToUnit(MapUnit unit, Spell.Spells spell, MapUnit target)
    {
        Spell cspell = unit.GetSpell(spell);

        if (cspell == null)
        {
            return;
        }

        if (cspell.Template.SpellTarget == 2)
        {
            SendCastToArea(unit, spell, target.X + target.Width / 2, target.Y + target.Height / 2);
            return;
        }

        if (NetworkManager.IsClient)
        {
            ServerCommands.CastToUnit cunitCmd;
            cunitCmd.TagFrom = unit.Tag;
            cunitCmd.SpellID = (int)spell;
            cunitCmd.TagTo   = target.Tag;
            ClientManager.SendCommand(cunitCmd);
        }
        else
        {
            if (MapLogic.Instance.ConsolePlayer == unit.Player)
            {
                unit.SetState(new CastState(unit, cspell, target));
            }
        }
    }
Beispiel #4
0
    static int RemapFromSpell(Spell.Spells spId)
    {
        for (int i = 0; i < SpellRemap.Length; i++)
        {
            if (SpellRemap[i] == spId)
            {
                return(i);
            }
        }

        return(-1);
    }
Beispiel #5
0
    //
    public Spell GetSpell(Spell.Spells spell)
    {
        foreach (Spell cspell in SpellBook)
        {
            if (cspell.SpellID == spell)
            {
                return(cspell);
            }
        }

        return(null);
    }
Beispiel #6
0
    Spell.Spells GetCastSpell()
    {
        if (SpellbookVisible && Spellbook.Unit == SelectedObject && Spellbook.ActiveSpell != Spell.Spells.NoneSpell)
        {
            Spell.Spells       sp  = Spellbook.ActiveSpell;
            Templates.TplSpell spl = TemplateLoader.GetSpellById((int)sp - 1);

            if (spl.SpellTarget == 2 ||
                (spl.SpellTarget == 1 && HoveredObject != null && (HoveredObject.GetObjectType() == MapObjectType.Human || HoveredObject.GetObjectType() == MapObjectType.Monster)))
            {
                return(Spellbook.ActiveSpell);
            }
        }
        return(Spell.Spells.NoneSpell);
    }
Beispiel #7
0
 public Wizard()
 {
     this.maxHealth     = 100;
     this.currentHealth = this.maxHealth;
     this.windForce     = 3;
     this.fireForce     = 3;
     this.waterForce    = 3;
     this.earthForce    = 3;
     this.wizardType    = WizardSchool.None;
     this.spell_1       = new Spell.WandAttack();
     this.spell_2       = new Spell.KniveAttack();
     this.spell_3       = new Spell.HomingBall();;
     this.spell_4       = new Spell.Heal();;
     this.name          = null;
     this.player        = true;
 }
Beispiel #8
0
    public Spell GetScrollEffect(MapUnit unit = null, Spell.Spells searchFor = Spell.Spells.NoneSpell)
    {
        foreach (ItemEffect eff in Effects)
        {
            if (eff.Type1 == ItemEffect.Effects.CastSpell)
            {
                if (searchFor != Spell.Spells.NoneSpell && eff.Value1 != (int)searchFor)
                {
                    continue;
                }
                Spell topSpell = new Spell(eff.Value1, unit);
                topSpell.Skill          = eff.Value2;
                topSpell.Item           = this;
                topSpell.ItemDisposable = true;
                return(topSpell);
            }
        }

        return(null);
    }
Beispiel #9
0
        public void useSpell(Spell.Spells usedSpell, Wizard target)
        {
            bool didHit = usedSpell.didHit();

            if (didHit)
            {
                Console.WriteLine(this.Name + " used " + usedSpell.SpellName);
                target.CurrentHealth = usedSpell.SpellPower;
                if (target.CurrentHealth > 100)
                {
                    target.CurrentHealth = target.CurrentHealth - target.MaxHealth;
                }
                if (!target.isAlive())
                {
                    Console.WriteLine("You defeted your enemy !");
                }
            }
            else
            {
                Console.WriteLine(this.Name + " missed " + usedSpell.SpellName);
            }
        }
Beispiel #10
0
    public bool ProcessEvent(Event e)
    {
        if (e.rawType == EventType.MouseDown ||
            e.rawType == EventType.MouseUp ||
            e.rawType == EventType.MouseMove)
        {
            int lw = 480;
            int lh = 85;

            Vector2 mPos      = Utils.GetMousePosition();
            Vector2 mPosLocal = mPos - new Vector2(transform.position.x, transform.position.y);
            if (mPosLocal.x < 0 || mPosLocal.y < 0 ||
                mPosLocal.x > lw || mPosLocal.y > lh)
            {
                return(false);
            }

            Vector2 spLocal = new Vector2((mPosLocal.x - 5) / 38, (mPosLocal.y - 5) / 38);
            int     spd     = (int)spLocal.y * 12 + (int)spLocal.x;
            if (spd > 24 || spd < 0)
            {
                spd = -1;
            }
            Spell.Spells sp = RemapToSpell(spd);

            if (e.rawType == EventType.MouseDown)
            {
                ActiveSpell = sp;
            }

            MouseCursor.SetCursor(MouseCursor.CurDefault);
            return(true);
        }

        return(false);
    }
    public void Update()
    {
        CurrentCommandActual &= EnabledCommands;
        CurrentCommand        = CurrentCommandActual;

        Spell.Spells viewCast = MapView.Instance.GetCastSpell();
        if (viewCast != Spell.Spells.NoneSpell)
        {
            CurrentCommand = Commands.Cast;
        }
        else if (CurrentCommandActual == Commands.Move)
        {
            // check if ctrl is pressed.
            // if alt is pressed, it's always Move overriding any other command.
            bool bAlt = (Input.GetKey(KeyCode.RightAlt) ||
                         Input.GetKey(KeyCode.LeftAlt));
            bool bCtrl = (Input.GetKey(KeyCode.RightControl) ||
                          Input.GetKey(KeyCode.LeftControl));

            if (bAlt && !bCtrl)
            {
                CurrentCommand = Commands.Move;
            }
            else if (bCtrl && !bAlt)
            {
                CurrentCommand = (MapView.Instance.HoveredObject != null &&
                                  (MapView.Instance.HoveredObject.GetObjectType() == MapObjectType.Monster ||
                                   MapView.Instance.HoveredObject.GetObjectType() == MapObjectType.Human)) ? Commands.Attack : Commands.MoveAttack;
            }
            else
            {
                // get own player
                Player ownPlayer = MapLogic.Instance.ConsolePlayer;
                Player hisPlayer = (MapView.Instance.HoveredObject != null &&
                                    (MapView.Instance.HoveredObject.GetObjectType() == MapObjectType.Monster ||
                                     MapView.Instance.HoveredObject.GetObjectType() == MapObjectType.Human)) ? ((IPlayerPawn)MapView.Instance.HoveredObject).GetPlayer() : null;
                if (ownPlayer != null && hisPlayer != null)
                {
                    if ((ownPlayer.Diplomacy[hisPlayer.ID] & DiplomacyFlags.Enemy) != 0)
                    {
                        CurrentCommand = Commands.Attack;
                    }
                }

                // check pickup
                // if selected unit == hovered unit
                // AND selected unit belongs to us
                // AND we are hovering a pack
                if (CurrentCommand == Commands.Move)
                {
                    MapSack sack = MapLogic.Instance.GetSackAt(MapView.Instance.MouseCellX, MapView.Instance.MouseCellY);
                    if (sack != null &&
                        (MapView.Instance.HoveredObject == MapView.Instance.SelectedObject || MapView.Instance.HoveredObject == null) &&
                        MapView.Instance.SelectedObject != null &&
                        MapView.Instance.SelectedObject is IPlayerPawn &&
                        ((IPlayerPawn)MapView.Instance.SelectedObject).GetPlayer() == ownPlayer)
                    {
                        CurrentCommand = Commands.Pickup;
                    }
                }
            }
        }

        // update visual button states
        for (int i = 0; i < 8; i++)
        {
            Commands icmd = (Commands)(1 << i);
            if ((EnabledCommands & icmd) != 0)
            {
                CommandBarDnObjects[i].SetActive(CurrentCommand == icmd);
                CommandBarUpObjects[i].SetActive(CurrentCommand != icmd);
            }
            else
            {
                CommandBarDnObjects[i].SetActive(false);
                CommandBarUpObjects[i].SetActive(false);
            }
        }
    }
Beispiel #12
0
        private ItemEffect GenerateEffect(Item item)
        {
            Random rnd          = new Random();
            float  itemPriceMax = 2 * PriceMax - item.Class.Price;
            float  manaMax      = item.Class.Material.MagicVolume * item.Class.Class.MagicVolume - item.ManaUsage;
            // note: this will not work correctly if SlotsWarrior or SlotsMage values for a slot are not sorted by ascending order.
            //       parameters that appear first will "override" parameters with the same weight appearing later.
            int lastValue;

            Templates.TplModifier lastModifier = TemplateLoader.Templates.Modifiers[TemplateLoader.Templates.Modifiers.Count - 1];
            if ((item.Class.Option.SuitableFor & 1) != 0)
            {
                lastValue = lastModifier.SlotsFighter[item.Class.Option.Slot - 1];
            }
            else
            {
                lastValue = lastModifier.SlotsMage[item.Class.Option.Slot - 1];
            }
            int randomValue = rnd.Next(0, lastValue) + 1;

            Templates.TplModifier matchingModifier = null;
            if (item.Class.Option.SuitableFor == 2 && item.Class.Option.Slot == 1)
            {
                matchingModifier = TemplateLoader.Templates.Modifiers[(int)ItemEffect.Effects.CastSpell];
            }
            else
            {
                for (int i = 1; i < TemplateLoader.Templates.Modifiers.Count; i++)
                {
                    Templates.TplModifier prevModifier = TemplateLoader.Templates.Modifiers[i - 1];
                    Templates.TplModifier modifier     = TemplateLoader.Templates.Modifiers[i];
                    int prevValue;
                    int value;
                    if ((item.Class.Option.SuitableFor & 1) != 0)
                    {
                        prevValue = prevModifier.SlotsFighter[item.Class.Option.Slot - 1];
                        value     = modifier.SlotsFighter[item.Class.Option.Slot - 1];
                    }
                    else
                    {
                        prevValue = prevModifier.SlotsMage[item.Class.Option.Slot - 1];
                        value     = modifier.SlotsMage[item.Class.Option.Slot - 1];
                    }
                    if (prevValue < randomValue && randomValue <= value)
                    {
                        matchingModifier = modifier;
                        break;
                    }
                }
            }
            if (matchingModifier == null)
            {
                // parameter not found. weird, but happens.
                return(null);
            }
            if ((matchingModifier.UsableBy & item.Class.Option.SuitableFor) == 0)
            {
                // parameter for class not found in the item.
                return(null);
            }
            // parameter found. calculate max possible power
            ItemEffect effect = new ItemEffect();

            effect.Type1 = (ItemEffect.Effects)matchingModifier.Index;
            float maxPower;
            float absoluteMax = manaMax / matchingModifier.ManaCost;

            if (matchingModifier.Index == (int)ItemEffect.Effects.CastSpell)
            {
                // select spell to cast.
                // if for fighter, choose between fighter-specific spells.
                // if for mage, choose between mage-specific spells.
                Spell.Spells[] spells;
                if ((item.Class.Option.SuitableFor & 1) != 0)
                {
                    spells = new Spell.Spells[] { Spell.Spells.Stone_Curse, Spell.Spells.Drain_Life }
                }
                ;
                else
                {
                    spells = new Spell.Spells[] { Spell.Spells.Fire_Arrow, Spell.Spells.Lightning, Spell.Spells.Prismatic_Spray, Spell.Spells.Stone_Curse, Spell.Spells.Drain_Life, Spell.Spells.Ice_Missile, Spell.Spells.Diamond_Dust }
                };
                // choose random spell
                Spell.Spells spell = spells[rnd.Next(0, spells.Length)];
                effect.Value1 = (int)spell;
                // calculate max power
                Templates.TplSpell spellTemplate = TemplateLoader.Templates.Spells[effect.Value1];
                maxPower = Mathf.Log(itemPriceMax / (spellTemplate.ScrollCost * 10f)) / Mathf.Log(2);
                if (!float.IsNaN(maxPower) && maxPower > 0)
                {
                    maxPower = (Mathf.Pow(1.2f, maxPower) - 1) * 30;
                }
                else
                {
                    return(null);
                }
                maxPower = Mathf.Min(maxPower, absoluteMax);
                maxPower = Mathf.Min(maxPower, 100);
            }
            else
            {
                maxPower = Mathf.Log(itemPriceMax / (manaMax * 50) - 1) / Mathf.Log(1.5f) * 70f / matchingModifier.ManaCost;
                if (float.IsNaN(maxPower))
                {
                    return(null);
                }
                maxPower = Mathf.Min(maxPower, absoluteMax);
                maxPower = Mathf.Min(maxPower, matchingModifier.AffectMax);
                if (maxPower < matchingModifier.AffectMin)
                {
                    return(null);
                }
            }

            if (maxPower <= 1)
            {
                // either some limit hit, or something else
                return(null);
            }

            // max parameter power found. randomize values
            switch (effect.Type1)
            {
            case ItemEffect.Effects.CastSpell:
                effect.Value2 = rnd.Next(1, (int)maxPower + 1);
                break;

            case ItemEffect.Effects.DamageFire:
            case ItemEffect.Effects.DamageWater:
            case ItemEffect.Effects.DamageAir:
            case ItemEffect.Effects.DamageEarth:
            case ItemEffect.Effects.DamageAstral:
                effect.Value1 = rnd.Next(1, (int)maxPower + 1);
                effect.Value2 = rnd.Next(1, (int)(maxPower / 2) + 1);
                break;

            default:
                effect.Value1 = (int)Mathf.Max(matchingModifier.AffectMin, rnd.Next(1, (int)maxPower + 1));
                break;
            }

            return(effect);
        }
Beispiel #13
0
 public SpellProcId(Spell.Spells id)
 {
     SpellID = (int)id;
 }
    public bool ProcessEvent(Event e)
    {
        if (e.rawType == EventType.MouseDown ||
            e.rawType == EventType.MouseUp ||
            e.rawType == EventType.MouseMove)
        {
            int lw = 480;
            int lh = 85;

            Vector2 mPos      = Utils.GetMousePosition();
            Vector2 mPosLocal = mPos - new Vector2(transform.position.x, transform.position.y);
            if (mPosLocal.x < 0 || mPosLocal.y < 0 ||
                mPosLocal.x > lw || mPosLocal.y > lh)
            {
                return(false);
            }

            Vector2 spLocal = new Vector2((mPosLocal.x - 5) / 38, (mPosLocal.y - 5) / 38);
            int     spd     = (int)spLocal.y * 12 + (int)spLocal.x;
            if (spd > 24 || spd < 0)
            {
                spd = -1;
            }
            Spell.Spells sp = RemapToSpell(spd);

            if (e.rawType == EventType.MouseDown)
            {
                ActiveSpell = sp;
                MapView.Instance.OneTimeCast = null;

                if (e.commandName == "double" && !Spell.IsAttackSpell(ActiveSpell))
                {
                    MapObject curObject = SelectedObject;
                    if (curObject is MapUnit)
                    {
                        Client.SendCastToUnit((MapUnit)curObject, new global::Spell((int)sp, (MapUnit)curObject), (MapUnit)curObject, curObject.X, curObject.Y);
                    }
                }
            }

            if (e.rawType == EventType.MouseMove &&
                e.commandName == "tooltip" &&
                (SpellsMask & (int)sp) != 0)
            {
                if (spd >= 0 && spd < Locale.Spells.Count)
                {
                    string    tt        = Locale.Spells[spd];
                    MapObject curObject = SelectedObject;
                    if (curObject is MapUnit)
                    {
                        tt += "\n" + new Spell((int)sp, (MapUnit)curObject).ToVisualString();
                    }
                    UiManager.Instance.SetTooltip(tt);
                }
            }

            MouseCursor.SetCursor(MouseCursor.CurDefault);
            return(true);
        }

        return(false);
    }
Beispiel #15
0
    public bool ProcessEvent(Event e)
    {
        if (!MapLogic.Instance.IsLoaded)
        {
            if (MapLogic.Instance.IsLoading)
            {
                MouseCursor.SetCursor(MouseCursor.CurWait);
            }
            return(false);
        }

        if (e.type == EventType.KeyDown)
        {
            switch (e.keyCode)
            {
            case KeyCode.LeftArrow:
                if (ScrollDeltaX == 0)
                {
                    ScrollDeltaX = -1;
                }
                return(true);

            case KeyCode.RightArrow:
                if (ScrollDeltaX == 0)
                {
                    ScrollDeltaX = 1;
                }
                return(true);

            case KeyCode.UpArrow:
                if (ScrollDeltaY == 0)
                {
                    ScrollDeltaY = -1;
                }
                return(true);

            case KeyCode.DownArrow:
                if (ScrollDeltaY == 0)
                {
                    ScrollDeltaY = 1;
                }
                return(true);

            case KeyCode.Plus:
            case KeyCode.Equals:     // + = =
            case KeyCode.KeypadPlus:
            {
                int oldSpeed = MapLogic.Instance.Speed;
                if (!NetworkManager.IsClient)
                {
                    MapLogic.Instance.Speed++;
                }
                if (oldSpeed != MapLogic.Instance.Speed)
                {
                    MapViewChat.Instance.AddChatMessage(Player.AllColorsSystem, Locale.Main[108 + MapLogic.Instance.Speed]);
                }
            }
                return(true);

            case KeyCode.Minus:
            case KeyCode.KeypadMinus:
            {
                int oldSpeed = MapLogic.Instance.Speed;
                if (!NetworkManager.IsClient)
                {
                    MapLogic.Instance.Speed--;
                }
                if (oldSpeed != MapLogic.Instance.Speed)
                {
                    MapViewChat.Instance.AddChatMessage(Player.AllColorsSystem, Locale.Main[108 + MapLogic.Instance.Speed]);
                }
            }
                return(true);

            case KeyCode.F3:
                //if (NetworkManager.IsClient)
            {
                DiplomacyWindow wnd = Utils.CreateObjectWithScript <DiplomacyWindow>();
                //Debug.LogFormat("created a window!");
            }
                return(true);

            case KeyCode.Escape:
            {
                // todo: create main menu
                ExampleWindow wnd = Utils.CreateObjectWithScript <ExampleWindow>();
            }
                return(true);

            case KeyCode.Space:
                // check if local unit is dead.
                // for dead local unit, space sends respawn.
                // for alive local unit, space toggles both spellbook and inventory.
                if (MapLogic.Instance.ConsolePlayer != null &&
                    !MapLogic.Instance.ConsolePlayer.Avatar.IsAlive)
                {
                    Client.SendRespawn();
                }
                else
                {
                    bool cstate = InventoryVisible && SpellbookVisible;
                    InventoryVisible = !cstate;
                    SpellbookVisible = !cstate;
                    Spellbook.Update();
                }
                return(true);

            case KeyCode.BackQuote:
                InventoryVisible = !InventoryVisible;
                Spellbook.Update();
                return(true);

            case KeyCode.Q:
                SpellbookVisible = !SpellbookVisible;
                Spellbook.Update();
                return(true);
            }
        }
        else if (e.type == EventType.KeyUp)
        {
            switch (e.keyCode)
            {
            case KeyCode.LeftArrow:
                if (ScrollDeltaX == -1)
                {
                    ScrollDeltaX = 0;
                }
                return(true);

            case KeyCode.RightArrow:
                if (ScrollDeltaX == 1)
                {
                    ScrollDeltaX = 0;
                }
                return(true);

            case KeyCode.UpArrow:
                if (ScrollDeltaY == -1)
                {
                    ScrollDeltaY = 0;
                }
                return(true);

            case KeyCode.DownArrow:
                if (ScrollDeltaY == 1)
                {
                    ScrollDeltaY = 0;
                }
                return(true);
            }
        }
        else if (e.rawType == EventType.MouseMove)
        {
            UpdateInput();
            return(true);
        }
        else if (e.rawType == EventType.MouseDown && e.button == 0)
        {
            // select unit if not selected yet
            // to-do: unfuck this expression later...
            if (HoveredObject != null &&
                (SelectedObject == null || (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move && GetCastSpell() == Spell.Spells.NoneSpell &&
                                            !Input.GetKey(KeyCode.LeftAlt) && !Input.GetKey(KeyCode.RightAlt)) || (Commandbar.CurrentCommand == 0)) &&
                (SelectedObject == null || !(HoveredObject is MapStructure s && s.Class.Usable)))
            {
                SelectedObject = HoveredObject;
            }
            else if (SelectedObject != null && SelectedObject is IPlayerPawn && ((IPlayerPawn)SelectedObject).GetPlayer() == MapLogic.Instance.ConsolePlayer)
            {
                // todo: handle commands here
                // try to walk.
                if (SelectedObject is MapUnit unit)
                {
                    Spell.Spells castSpId = GetCastSpell();
                    if (HoveredObject is MapStructure struc && struc.Class.Usable)
                    {
                        Client.SendUseStructure(unit, struc);
                    }
                    else if (castSpId != Spell.Spells.NoneSpell && (MapLogic.Instance.Nodes[MouseCellX, MouseCellY].Flags & MapNodeFlags.Visible) != 0)
                    {
                        Spell castSp = GetOneTimeCast();
                        if (castSp == null)
                        {
                            castSp = unit.GetSpell(castSpId);
                        }
                        if (HoveredObject != null && HoveredObject is MapUnit)
                        {
                            Client.SendCastToUnit(unit, castSp, (MapUnit)HoveredObject, MouseCellX, MouseCellY);
                        }
                        else
                        {
                            Client.SendCastToArea(unit, castSp, MouseCellX, MouseCellY);
                        }
                        if (castSp == OneTimeCast || Commandbar.CurrentCommandActual == MapViewCommandbar.Commands.Cast)
                        {
                            SpellbookVisible = false;
                            if (Commandbar.CurrentCommandActual == MapViewCommandbar.Commands.Cast)
                            {
                                Commandbar.InitDefault(SelectedObject);
                            }
                        }
                        OneTimeCast = null;
                    }
                    else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Move)
                    {
                        Client.SendMoveUnit(unit, MouseCellX, MouseCellY);
                    }
                    else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Attack &&
                             HoveredObject != null &&
                             HoveredObject is MapUnit)
                    {
                        Client.SendAttackUnit(unit, (MapUnit)HoveredObject);
                    }
                    else if (Commandbar.CurrentCommand == MapViewCommandbar.Commands.Pickup &&
                             MapLogic.Instance.GetSackAt(MouseCellX, MouseCellY) != null)
                    {
                        Client.SendPickupUnit(unit, MouseCellX, MouseCellY); // issue sack pickup command by current unit at target coordinates
                    }
                }
            }