Exemple #1
0
        /// <summary>
        /// Called when the character casts the spell
        /// </summary>
        public virtual bool Cast(float x, float y, float x2, float y2, AttackableUnit u = null)
        {
            if (HasEmptyScript)
            {
                return(false);
            }

            var stats = Owner.Stats;

            if (SpellData.ManaCost[Level] * (1 - stats.SpellCostReduction) >= stats.CurrentMana ||
                State != SpellState.STATE_READY)
            {
                return(false);
            }

            if (_game.Config.ManaCostsEnabled)
            {
                stats.CurrentMana = stats.CurrentMana - SpellData.ManaCost[Level] * (1 - stats.SpellCostReduction);
            }

            X               = x;
            Y               = y;
            X2              = x2;
            Y2              = y2;
            Target          = u;
            FutureProjNetId = _networkIdManager.GetNewNetId();
            SpellNetId      = _networkIdManager.GetNewNetId();

            if (SpellData.TargettingType == 1 && Target != null && Target.GetDistanceTo(Owner) > SpellData.CastRange[Level])
            {
                return(false);
            }

            _spellGameScript.OnStartCasting(Owner, this, Target);

            if (SpellData.GetCastTime() > 0 && (SpellData.Flags & (int)SpellFlag.SPELL_FLAG_INSTANT_CAST) == 0)
            {
                Owner.SetPosition(Owner.X, Owner.Y); //stop moving serverside too. TODO: check for each spell if they stop movement or not
                State           = SpellState.STATE_CASTING;
                CurrentCastTime = SpellData.GetCastTime();
            }
            else
            {
                FinishCasting();
            }

            _game.PacketNotifier.NotifyCastSpell(_game.Map.NavGrid, this, x, y, x2, y2, FutureProjNetId, SpellNetId);
            return(true);
        }
Exemple #2
0
        public GameObject(Game game, float x, float y, int collisionRadius, int visionRadius = 0, uint netId = 0) : base(x, y)
        {
            _game             = game;
            _networkIdManager = game.NetworkIdManager;
            if (netId != 0)
            {
                NetId = netId; // Custom netId
            }
            else
            {
                NetId = _networkIdManager.GetNewNetId(); // Let the base class (this one) asign a netId
            }
            Target          = null;
            CollisionRadius = collisionRadius;
            VisionRadius    = visionRadius;
            Waypoints       = new List <Vector2>();

            _visibleByTeam = new Dictionary <TeamId, bool>();
            var teams = Enum.GetValues(typeof(TeamId)).Cast <TeamId>();

            foreach (var team in teams)
            {
                _visibleByTeam.Add(team, false);
            }

            Team             = TeamId.TEAM_NEUTRAL;
            _movementUpdated = false;
            _toRemove        = false;
            AttackerCount    = 0;
            IsDashing        = false;
        }
Exemple #3
0
        /// <summary>
        /// Called when the character casts the spell
        /// </summary>
        public virtual bool Cast(float x, float y, float x2, float y2, IAttackableUnit u = null)
        {
            if (HasEmptyScript)
            {
                return(false);
            }
            if (Owner.IsCastingSpell)
            {
                return(false);
            }
            var stats = Owner.Stats;

            if (SpellData.ManaCost[Level] * (1 - stats.SpellCostReduction) >= stats.CurrentMana ||
                State != SpellState.STATE_READY)
            {
                return(false);
            }

            if (_game.Config.ManaCostsEnabled)
            {
                stats.CurrentMana = stats.CurrentMana - SpellData.ManaCost[Level] * (1 - stats.SpellCostReduction);
            }

            X                = x;
            Y                = y;
            X2               = x2;
            Y2               = y2;
            Target           = u;
            _futureProjNetId = _networkIdManager.GetNewNetId();
            Projectiles      = new Dictionary <uint, IProjectile>();
            SpellNetId       = _networkIdManager.GetNewNetId();

            if (SpellData.TargettingType == 1 && Target != null && Target.GetDistanceTo(Owner) > SpellData.CastRange[Level])
            {
                return(false);
            }
            if (RefItem != null)
            {
                DecraseStacks();
            }
            var newF = int.Parse(Convert.ToString(SpellData.Flags, 8));

            _spellGameScript.OnStartCasting(Owner, this, Target);
            if (SpellData.GetCastTime() > 0 && (SpellData.Flags & (int)SpellFlag.SPELL_FLAG_INSTANT_CAST) == 0)
            {
                Owner.SetPosition(Owner.X, Owner.Y); //stop moving serverside too. TODO: check for each spell if they stop movement or not
                State           = SpellState.STATE_CASTING;
                CurrentCastTime = SpellData.GetCastTime();
            }
            else
            {
                FinishCasting();
            }

            _game.PacketNotifier.NotifyNPC_CastSpellAns(_game.Map.NavigationGrid, this, new Vector2(x, y), new Vector2(x2, y2), _futureProjNetId);
            return(true);
        }
Exemple #4
0
        public override bool HandlePacket(int userId, byte[] data)
        {
            _game.PacketNotifier.NotifySpawnStart(userId);
            _logger.Debug("Spawning map");

            var playerId = 0;

            foreach (var p in _playerManager.GetPlayers())
            {
                _game.PacketNotifier.NotifyHeroSpawn(userId, p.Item2, playerId++);
                _game.PacketNotifier.NotifyAvatarInfo(userId, p.Item2);
            }

            var peerInfo     = _playerManager.GetPeerInfo(userId);
            var bluePill     = _itemManager.GetItemType(_game.Map.MapGameScript.BluePillId);
            var itemInstance = peerInfo.Champion.Inventory.SetExtraItem(7, bluePill);

            _game.PacketNotifier.NotifyBuyItem(userId, peerInfo.Champion, itemInstance);

            // Runes
            byte runeItemSlot = 14;

            foreach (var rune in peerInfo.Champion.RuneList.Runes)
            {
                var runeItem = _itemManager.GetItemType(rune.Value);
                var newRune  = peerInfo.Champion.Inventory.SetExtraItem(runeItemSlot, runeItem);
                _playerManager.GetPeerInfo(userId).Champion.Stats.AddModifier(runeItem);
                runeItemSlot++;
            }

            // Not sure why both 7 and 14 skill slot, but it does not seem to work without it
            _game.PacketNotifier.NotifySkillUp(userId, peerInfo.Champion.NetId, 7, 1, peerInfo.Champion.SkillPoints);
            _game.PacketNotifier.NotifySkillUp(userId, peerInfo.Champion.NetId, 14, 1, peerInfo.Champion.SkillPoints);

            peerInfo.Champion.Stats.SetSpellEnabled(7, true);
            peerInfo.Champion.Stats.SetSpellEnabled(14, true);
            peerInfo.Champion.Stats.SetSummonerSpellEnabled(0, true);
            peerInfo.Champion.Stats.SetSummonerSpellEnabled(1, true);

            var objects = _game.ObjectManager.GetObjects();

            foreach (var kv in objects)
            {
                if (kv.Value is LaneTurret turret)
                {
                    _game.PacketNotifier.NotifyTurretSpawn(userId, turret);

                    // Fog Of War
                    _game.PacketNotifier.NotifyFogUpdate2(turret, _networkIdManager.GetNewNetId());

                    // To suppress game HP-related errors for enemy turrets out of vision
                    _game.PacketNotifier.NotifySetHealth(userId, turret);

                    foreach (var item in turret.Inventory)
                    {
                        if (item == null)
                        {
                            continue;
                        }
                        _game.PacketNotifier.NotifyItemBought(turret, item as Item);
                    }
                }
                else if (kv.Value is LevelProp levelProp)
                {
                    _game.PacketNotifier.NotifyLevelPropSpawn(userId, levelProp);
                }
                else if (kv.Value is Champion champion)
                {
                    if (champion.IsVisibleByTeam(peerInfo.Champion.Team))
                    {
                        _game.PacketNotifier.NotifyEnterVision(userId, champion);
                    }
                }
                else if (kv.Value is Inhibitor || kv.Value is Nexus)
                {
                    var inhibtor = (AttackableUnit)kv.Value;
                    _game.PacketNotifier.NotifyStaticObjectSpawn(userId, inhibtor.NetId);
                    _game.PacketNotifier.NotifySetHealth(userId, inhibtor.NetId);
                }
                else if (kv.Value is Projectile projectile)
                {
                    if (projectile.IsVisibleByTeam(peerInfo.Champion.Team))
                    {
                        _game.PacketNotifier.NotifyProjectileSpawn(userId, projectile);
                    }
                }
                else
                {
                    _logger.Warn("Object of type: " + kv.Value.GetType() + " not handled in HandleSpawn.");
                }
            }

            // TODO shop map specific?
            // Level props are just models, we need button-object minions to allow the client to interact with it
            if (peerInfo != null && peerInfo.Team == TeamId.TEAM_BLUE)
            {
                // Shop (blue team)
                _game.PacketNotifier.NotifyStaticObjectSpawn(userId, 0xff10c6db);
                _game.PacketNotifier.NotifySetHealth(userId, 0xff10c6db);
            }
            else if (peerInfo != null && peerInfo.Team == TeamId.TEAM_PURPLE)
            {
                // Shop (purple team)
                _game.PacketNotifier.NotifyStaticObjectSpawn(userId, 0xffa6170e);
                _game.PacketNotifier.NotifySetHealth(userId, 0xffa6170e);
            }

            _game.PacketNotifier.NotifySpawnEnd(userId);
            return(true);
        }