Ejemplo n.º 1
0
        public bool Initialize(Address address, string baseKey)
        {
            _logger.LogCoreInfo("Loading Config.");
            Config = new Config("Settings/GameInfo.json");

            _server = new Host();
            _server.Create(address, 32, 32, 0, 0);

            var key = System.Convert.FromBase64String(baseKey);

            if (key.Length <= 0)
            {
                return(false);
            }

            Blowfish             = new BlowFish(key);
            PacketHandlerManager = new PacketHandlerManager(_logger, Blowfish, _server, _playerManager);
            Map            = new SummonersRift(this);
            PacketNotifier = new PacketNotifier(this, _playerManager, _networkIdManager);
            ApiFunctionManager.SetGame(this);
            IsRunning = false;

            foreach (var p in Config.Players)
            {
                _playerManager.AddPlayer(p);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public unsafe bool HandlePacket(ENetPeer *peer, byte[] data, Game game)
        {
            var sell   = new SellItem(data);
            var client = game.getPeerInfo(peer);

            var i = game.getPeerInfo(peer).getChampion().getInventory().getItemSlot(sell.slotId);

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

            float sellPrice = i.getTemplate().getTotalPrice() * i.getTemplate().getSellBackModifier();

            client.getChampion().getStats().setGold(client.getChampion().getStats().getGold() + sellPrice);

            if (i.getTemplate().getMaxStack() > 1)
            {
                i.decrementStacks();
                PacketNotifier.notifyRemoveItem(client.getChampion(), sell.slotId, i.getStacks());

                if (i.getStacks() == 0)
                {
                    client.getChampion().getInventory().removeItem(sell.slotId);
                }
            }
            else
            {
                PacketNotifier.notifyRemoveItem(client.getChampion(), sell.slotId, 0);
                client.getChampion().getInventory().removeItem(sell.slotId);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public void addProjectileTarget(Target target)
        {
            Projectile p = new Projectile(owner.getMap(), Game.GetNewNetID(), owner.getX(), owner.getY(), (int)lineWidth, owner, target, this, projectileSpeed, (int)RAFManager.getInstance().getHash(spellName + "Missile"), projectileFlags != 0 ? projectileFlags : flags);

            owner.getMap().addObject(p);
            PacketNotifier.notifyProjectileSpawn(p);
        }
Ejemplo n.º 4
0
        public void GameLoop()
        {
            _lastMapDurationWatch = new Stopwatch();
            _lastMapDurationWatch.Start();
            while (!SetToExit)
            {
                _packetServer.NetLoop();
                if (IsPaused)
                {
                    _lastMapDurationWatch.Stop();
                    _pauseTimer.Enabled = true;
                    if (PauseTimeLeft <= 0 && !_autoResumeCheck)
                    {
                        PacketNotifier.NotifyUnpauseGame();
                        _autoResumeCheck = true;
                    }
                    continue;
                }

                if (_lastMapDurationWatch.Elapsed.TotalMilliseconds + 1.0 > REFRESH_RATE)
                {
                    var sinceLastMapTime = _lastMapDurationWatch.Elapsed.TotalMilliseconds;
                    _lastMapDurationWatch.Restart();
                    if (IsRunning)
                    {
                        Update((float)sinceLastMapTime);
                    }
                }
                Thread.Sleep(1);
            }
        }
Ejemplo n.º 5
0
        public void Initialize(Address address, string blowfishKey, Config config)
        {
            _logger.LogCoreInfo("Loading Config.");
            Config = config;

            _chatCommandManager.LoadCommands();
            _server = new Host();
            _server.Create(address, 32, 32, 0, 0);

            var key = Convert.FromBase64String(blowfishKey);

            if (key.Length <= 0)
            {
                throw new InvalidKeyException("Invalid blowfish key supplied");
            }

            Blowfish             = new BlowFish(key);
            PacketHandlerManager = new PacketHandlerManager(_logger, Blowfish, _server, _playerManager);

            RegisterMap((byte)Config.GameConfig.Map);

            PacketNotifier = new PacketNotifier(this, _playerManager, _networkIdManager);
            ApiFunctionManager.SetGame(this);
            IsRunning = false;

            foreach (var p in Config.Players)
            {
                _playerManager.AddPlayer(p);
            }


            _logger.LogCoreInfo("Game is ready.");
        }
Ejemplo n.º 6
0
        public unsafe bool HandlePacket(ENetPeer *peer, byte[] data, Game game)
        {
            var request = new BuyItemReq(data);

            var itemTemplate = ItemManager.getInstance().getItemTemplateById(request.id);

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

            var          recipeParts = game.getPeerInfo(peer).getChampion().getInventory().getAvailableRecipeParts(itemTemplate);
            var          price       = itemTemplate.getTotalPrice();
            ItemInstance i;

            if (recipeParts.Count == 0)
            {
                if (game.getPeerInfo(peer).getChampion().getStats().getGold() < price)
                {
                    return(true);
                }

                i = game.getPeerInfo(peer).getChampion().getInventory().addItem(itemTemplate);

                if (i == null)
                { // Slots full
                    return(false);
                }
            }
            else
            {
                foreach (var instance in recipeParts)
                {
                    price -= instance.getTemplate().getTotalPrice();
                }

                if (game.getPeerInfo(peer).getChampion().getStats().getGold() < price)
                {
                    return(false);
                }


                foreach (var instance in recipeParts)
                {
                    game.getPeerInfo(peer).getChampion().getStats().unapplyStatMods(instance.getTemplate().getStatMods());
                    PacketNotifier.notifyRemoveItem(game.getPeerInfo(peer).getChampion(), instance.getSlot(), 0);
                    game.getPeerInfo(peer).getChampion().getInventory().removeItem(instance.getSlot());
                }

                i = game.getPeerInfo(peer).getChampion().getInventory().addItem(itemTemplate);
            }

            game.getPeerInfo(peer).getChampion().getStats().setGold(game.getPeerInfo(peer).getChampion().getStats().getGold() - price);
            game.getPeerInfo(peer).getChampion().getStats().applyStatMods(itemTemplate.getStatMods());
            PacketNotifier.notifyItemBought(game.getPeerInfo(peer).getChampion(), i);

            return(true);
        }
Ejemplo n.º 7
0
 public void Pause()
 {
     if (PauseTimeLeft <= 0)
     {
         return;
     }
     IsPaused = true;
     PacketNotifier.NotifyPauseGame((int)PauseTimeLeft, true);
 }
Ejemplo n.º 8
0
 public DummyGame()
 {
     _blowfish             = new BlowFish(Encoding.Default.GetBytes("UnitTests stinks"));
     _packetHandlerManager = new PacketHandlerManager(this);
     _map            = new Map(this, 1, 1, 1, true, 1);
     _packetNotifier = new PacketNotifier(this);
     _server         = new Host();
     _server.Create(12345, 123);
 }
Ejemplo n.º 9
0
 protected void keepFocussingTarget()
 {
     if (isAttacking && (targetUnit == null || distanceWith(targetUnit) > stats.getRange()))
     // If target is dead or out of range
     {
         PacketNotifier.notifyStopAutoAttack(this);
         isAttacking = false;
     }
 }
Ejemplo n.º 10
0
        public void Initialize(Address address, string blowfishKey, Config config)
        {
            _logger.LogCoreInfo("Loading Config.");
            Config = config;

            _gameScriptTimers = new List <GameScriptTimer>();

            _chatCommandManager.LoadCommands();
            _server = new Host();
            _server.Create(address, 32, 32, 0, 0);

            var key = Convert.FromBase64String(blowfishKey);

            if (key.Length <= 0)
            {
                throw new InvalidKeyException("Invalid blowfish key supplied");
            }

            Blowfish             = new BlowFish(key);
            PacketHandlerManager = new PacketHandlerManager(_logger, Blowfish, _server, _playerManager,
                                                            _packetHandlerProvider);


            ObjectManager = new ObjectManager(this);
            Map           = new Map(this);

            PacketNotifier = new PacketNotifier(this, _playerManager, _networkIdManager);
            ApiFunctionManager.SetGame(this);
            ApiEventManager.SetGame(this);
            IsRunning           = false;
            disconnectedPlayers = 0;

            _logger.LogCoreInfo("Loading C# Scripts");

            LoadScripts();

            Map.Init();

            foreach (var p in Config.Players)
            {
                _playerManager.AddPlayer(p);
            }

            _pauseTimer = new Timer
            {
                AutoReset = true,
                Enabled   = false,
                Interval  = 1000
            };
            _pauseTimer.Elapsed += (sender, args) => PauseTimeLeft--;
            PauseTimeLeft        = 30 * 60; // 30 minutes

            _logger.LogCoreInfo("Game is ready.");
        }
Ejemplo n.º 11
0
        public override void setToRemove()
        {
            if (target != null && !target.isSimpleTarget())
            {
                (target as GameObject).decrementAttackerCount();
            }

            owner.decrementAttackerCount();
            base.setToRemove();
            PacketNotifier.notifyProjectileDestroy(this);
        }
Ejemplo n.º 12
0
        public virtual void die(Unit killer)
        {
            setToRemove();
            map.stopTargeting(this);

            PacketNotifier.notifyNpcDie(this, killer);

            float exp    = map.getExperienceFor(this);
            var   champs = map.getChampionsInRange(this, EXP_RANGE, true);

            //Cull allied champions
            champs.RemoveAll(l => l.getTeam() == getTeam());

            if (champs.Count > 0)
            {
                float expPerChamp = exp / champs.Count;
                foreach (var c in champs)
                {
                    c.getStats().setExp(c.getStats().getExperience() + expPerChamp);
                }
            }

            if (killer != null)
            {
                var cKiller = killer as Champion;

                if (cKiller == null)
                {
                    return;
                }

                float gold = map.getGoldFor(this);
                if (gold <= 0)
                {
                    return;
                }

                cKiller.getStats().setGold(cKiller.getStats().getGold() + gold);
                PacketNotifier.notifyAddGold(cKiller, this, gold);

                if (cKiller.killDeathCounter < 0)
                {
                    cKiller.setChampionGoldFromMinions(cKiller.getChampionGoldFromMinions() + gold);
                    Logger.LogCoreInfo("Adding gold form minions to reduce death spree: " + cKiller.getChampionGoldFromMinions());
                }

                if (cKiller.getChampionGoldFromMinions() >= 50 && cKiller.killDeathCounter < 0)
                {
                    cKiller.setChampionGoldFromMinions(0);
                    cKiller.killDeathCounter += 1;
                }
            }
        }
Ejemplo n.º 13
0
 public Buff(string buffName, float dur, BuffType type, Unit u, Unit attacker)
 {
     this.duration    = dur;
     this.name        = buffName;
     this.timeElapsed = 0;
     this.remove      = false;
     this.attachedTo  = u;
     this.attacker    = attacker;
     this.buffType    = type;
     this.movementSpeedPercentModifier = 0.0f;
     PacketNotifier.notifyAddBuff(u, attacker, buffName);
 }
Ejemplo n.º 14
0
 public Buff(string buffName, float dur, BuffType type, Unit u) //no attacker specified = selfbuff, attacker aka source is same as attachedto
 {
     this.duration    = dur;
     this.name        = buffName;
     this.timeElapsed = 0;
     this.remove      = false;
     this.attachedTo  = u;
     this.attacker    = u;
     this.buffType    = type;
     this.movementSpeedPercentModifier = 0.0f;
     PacketNotifier.notifyAddBuff(u, attacker, buffName);
 }
Ejemplo n.º 15
0
        public void addObject(GameObject o)
        {
            if (o == null)
            {
                return;
            }

            lock (objects)
                objects.Add(o.getNetId(), o);

            var u = o as Unit;

            if (u == null)
            {
                return;
            }

            collisionHandler.addObject(o);
            var team       = o.getTeam();
            var teamVision = visionUnits[Convert.fromTeamId(team)];

            if (teamVision.ContainsKey(o.getNetId()))
            {
                teamVision[o.getNetId()] = u;
            }
            else
            {
                teamVision.Add(o.getNetId(), u);
            }

            var m = u as Minion;

            if (m != null)
            {
                PacketNotifier.notifyMinionSpawned(m, m.getTeam());
            }

            var mo = u as Monster;

            if (mo != null)
            {
                PacketNotifier.notifySpawn(mo);
            }

            var c = o as Champion;

            if (c != null)
            {
                champions[c.getNetId()] = c;
                PacketNotifier.notifyChampionSpawned(c, c.getTeam());
            }
        }
Ejemplo n.º 16
0
        public bool Initialize(Address address, string baseKey)
        {
            Logger.LogCoreInfo("Loading Config.");
            Config = new Config("Settings/GameInfo.json");

            ItemManager    = ItemManager.LoadItems(this);
            ChatboxManager = new ChatboxManager(this);

            _server = new Host();
            _server.Create(address, 32, 32, 0, 0);

            var key = System.Convert.FromBase64String(baseKey);

            if (key.Length <= 0)
            {
                return(false);
            }

            Blowfish             = new BlowFish(key);
            PacketHandlerManager = new PacketHandlerManager(this);
            _map           = new SummonersRift(this);
            PacketNotifier = new PacketNotifier(this);
            ApiFunctionManager.SetGame(this);

            var id = 1;

            foreach (var p in Config.Players)
            {
                var player = new ClientInfo(p.Value.Rank, ((p.Value.Team.ToLower() == "blue") ? TeamId.TEAM_BLUE : TeamId.TEAM_PURPLE), p.Value.Ribbon, p.Value.Icon);

                player.SetName(p.Value.Name);

                player.SetSkinNo(p.Value.Skin);
                player.UserId = id; // same as StartClient.bat
                id++;

                player.SetSummoners(StrToId(p.Value.Summoner1), StrToId(p.Value.Summoner2));

                var c   = new Champion(this, p.Value.Champion, GetNewNetID(), (uint)player.UserId);
                var pos = c.getRespawnPosition();

                c.setPosition(pos.Item1, pos.Item2);
                c.setTeam((p.Value.Team.ToLower() == "blue") ? TeamId.TEAM_BLUE : TeamId.TEAM_PURPLE);
                c.LevelUp();

                player.SetChampion(c);
                var pair = new Pair <uint, ClientInfo>();
                pair.Item2 = player;
                _players.Add(pair);
            }
            return(true);
        }
Ejemplo n.º 17
0
        public bool HandleDisconnect(int userId)
        {
            var peerinfo = PlayerManager.GetPeerInfo(userId);

            if (peerinfo != null)
            {
                if (!peerinfo.IsDisconnected)
                {
                    PacketNotifier.NotifyUnitAnnounceEvent(UnitAnnounces.SUMMONER_DISCONNECTED, peerinfo.Champion);
                }
                peerinfo.IsDisconnected = true;
            }
            return(true);
        }
Ejemplo n.º 18
0
        private bool HandleDisconnect(Peer peer)
        {
            var peerinfo = _playerManager.GetPeerInfo(peer);

            if (peerinfo != null)
            {
                if (!peerinfo.IsDisconnected)
                {
                    PacketNotifier.NotifyUnitAnnounceEvent(UnitAnnounces.SummonerDisconnected, peerinfo.Champion);
                }
                peerinfo.IsDisconnected = true;
            }
            return(true);
        }
Ejemplo n.º 19
0
        public unsafe bool HandlePacket(ENetPeer *peer, byte[] data, Game game)
        {
            var request = new SwapItems(data);

            if (request.slotFrom > 6 || request.slotTo > 6)
            {
                return(false);
            }

            game.getPeerInfo(peer).getChampion().getInventory().swapItems(request.slotFrom, request.slotTo);
            PacketNotifier.notifyItemsSwapped(game.getPeerInfo(peer).getChampion(), request.slotFrom, request.slotTo);

            return(true);
        }
Ejemplo n.º 20
0
        public void Update(float diff)
        {
            GameTime += diff;
            ((ObjectManager)ObjectManager).Update(diff);
            Map.Update(diff);
            _gameScriptTimers.ForEach(gsTimer => gsTimer.Update(diff));
            _gameScriptTimers.RemoveAll(gsTimer => gsTimer.IsDead());

            // By default, synchronize the game time every 10 seconds
            _nextSyncTime += diff;
            if (_nextSyncTime >= 10 * 1000)
            {
                PacketNotifier.NotifyGameTimer(GameTime);
                _nextSyncTime = 0;
            }
        }
Ejemplo n.º 21
0
        /**
         * Called when the spell is finished casting and we're supposed to do things
         * such as projectile spawning, etc.
         */
        public virtual void finishCasting()
        {
            doLua();

            state           = SpellState.STATE_COOLDOWN;
            currentCooldown = getCooldown();

            var current    = new Vector2(owner.getX(), owner.getY());
            var to         = (new Vector2(x, y) - current);
            var trueCoords = current + (Vector2.Normalize(to) * 1150);

            var p = new Projectile(owner.getMap(), Game.GetNewNetID(), owner.getX(), owner.getY(), (int)lineWidth, owner, new Target(trueCoords.X, trueCoords.Y), this, projectileSpeed, (int)RAFHashManager.GetHash(spellName + "Missile"), projectileFlags > 0 ? (int)projectileFlags : flags);

            owner.getMap().addObject(p);
            PacketNotifier.notifyProjectileSpawn(p);
        }
Ejemplo n.º 22
0
        public void Initialize(Config config, PacketServer server)
        {
            _logger.Info("Loading Config.");
            Config = config;

            _gameScriptTimers = new List <GameScriptTimer>();

            ChatCommandManager.LoadCommands();

            ObjectManager = new ObjectManager(this);
            Map           = new Map(this);
            ApiFunctionManager.SetGame(this);
            ApiEventManager.SetGame(this);
            IsRunning = false;

            _logger.Info("Loading C# Scripts");

            LoadScripts();

            Map.Init();

            _logger.Info("Add players");
            foreach (var p in Config.Players)
            {
                ((PlayerManager)PlayerManager).AddPlayer(p);
            }

            _pauseTimer = new Timer
            {
                AutoReset = true,
                Enabled   = false,
                Interval  = 1000
            };
            _pauseTimer.Elapsed += (sender, args) => PauseTimeLeft--;
            PauseTimeLeft        = 30 * 60; // 30 minutes

            // TODO: GameApp should send the Response/Request handlers
            _packetServer = server;
            // TODO: switch the notifier with ResponseHandler
            PacketNotifier = new PacketNotifier(_packetServer.PacketHandlerManager, Map.NavGrid);
            InitializePacketHandlers();

            _logger.Info("Game is ready.");
        }
Ejemplo n.º 23
0
        public void Initialize(ushort port, string blowfishKey, Config config)
        {
            _logger.Info("Loading Config.");
            Config = config;

            _gameScriptTimers = new List <GameScriptTimer>();

            ChatCommandManager.LoadCommands();

            ObjectManager = new ObjectManager(this);
            Map           = new Map(this);
            ApiFunctionManager.SetGame(this);
            ApiEventManager.SetGame(this);
            IsRunning = false;

            _logger.Info("Loading C# Scripts");

            LoadScripts();

            Map.Init();

            _logger.Info("Add players");
            foreach (var p in Config.Players)
            {
                ((PlayerManager)PlayerManager).AddPlayer(p);
            }

            _pauseTimer = new Timer
            {
                AutoReset = true,
                Enabled   = false,
                Interval  = 1000
            };
            _pauseTimer.Elapsed += (sender, args) => PauseTimeLeft--;
            PauseTimeLeft        = 30 * 60; // 30 minutes

            _packetServer = new PacketServer();
            _packetServer.InitServer(port, blowfishKey, this);
            PacketNotifier = new PacketNotifier(_packetServer.PacketHandlerManager, Map.NavGrid);
            // TODO: make lib to only get API types and not byte[], start from removing this line
            PacketReader = new PacketReader();

            _logger.Info("Game is ready.");
        }
Ejemplo n.º 24
0
        public void stopTargeting(Unit target)
        {
            foreach (var kv in objects)
            {
                var u = kv.Value as Unit;

                if (u == null)
                {
                    continue;
                }

                if (u.getTargetUnit() == target)
                {
                    u.setTargetUnit(null);
                    u.setAutoAttackTarget(null);
                    PacketNotifier.notifySetTarget(u, null);
                }
            }
        }
Ejemplo n.º 25
0
        private bool HandleDisconnect(Peer peer)
        {
            var peerinfo = _playerManager.GetPeerInfo(peer);

            if (peerinfo != null)
            {
                if (!peerinfo.IsDisconnected)
                {
                    PacketNotifier.NotifyUnitAnnounceEvent(UnitAnnounces.SummonerDisconnected, peerinfo.Champion);
                }
                _logger.LogCoreInfo("somebody disconnected");
                disconnectedPlayers++;
                var number = _playerManager.GetPlayers().Count - disconnectedPlayers;
                _logger.LogCoreInfo(number.ToString());
                if (number == 0)
                {
                    _logger.LogCoreInfo("no players connected");
                    Program.SetToExit();
                }
                peerinfo.IsDisconnected = true;
            }
            return(true);
        }
Ejemplo n.º 26
0
        public void update(long diff)
        {
            timeElapsed += (float)diff / 1000.0f;

            //F**k LUA

            /*  if (buffScript != null && buffScript.isLoaded())
             * {
             *    buffScript.lua.get<sol::function>("onUpdate").call<void>(diff);
             * }*/

            if (getBuffType() != BuffType.BUFFTYPE_ETERNAL)
            {
                if (timeElapsed >= duration)
                {
                    if (name != "")
                    { // empty name = no buff icon
                        PacketNotifier.notifyRemoveBuff(attachedTo, name);
                    }
                    remove = true;
                }
            }
        }
Ejemplo n.º 27
0
        // AI tasks
        protected bool scanForTargets()
        {
            Unit   nextTarget         = null;
            double nextTargetPriority = 9e5;

            var objects = map.getObjects();

            foreach (var it in objects)
            {
                var u = it.Value as Unit;

                // Targets have to be:
                if (u == null ||                             // a unit
                    u.isDead() ||                            // alive
                    u.getTeam() == getTeam() ||              // not on our team
                    distanceWith(u) > DETECT_RANGE ||        // in range
                    !getMap().teamHasVisionOn(getTeam(), u)) // visible to this minion
                {
                    continue;                                // If not, look for something else
                }
                var priority = classifyTarget(u);            // get the priority.
                if (priority < nextTargetPriority)           // if the priority is lower than the target we checked previously
                {
                    nextTarget         = u;                  // make him a potential target.
                    nextTargetPriority = priority;
                }
            }

            if (nextTarget != null)        // If we have a target
            {
                setTargetUnit(nextTarget); // Set the new target and refresh waypoints
                PacketNotifier.notifySetTarget(this, nextTarget);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 28
0
        private const double REFRESH_RATE    = 16.666; // 60 fps

        public bool initialize(ENetAddress address, string baseKey)
        {
            if (enet_initialize() < 0)
            {
                return(false);
            }

            _server = enet_host_create(&address, new IntPtr(32), new IntPtr(32), 0, 0);
            if (_server == null)
            {
                return(false);
            }

            var key = System.Convert.FromBase64String(baseKey);

            if (key.Length <= 0)
                return(false);

            fixed(byte *s = key)
            {
                _blowfish = BlowFishCS.BlowFishCS.BlowFishCreate(s, new IntPtr(16));
            }

            PacketHandlerManager.getInstace().InitHandlers(this);

            map = new SummonersRift(this);

            PacketNotifier.setMap(map);
            //TODO: better lua implementation

            var id = 1;

            foreach (var p in Config.players)
            {
                var player = new ClientInfo(p.Value.rank, ((p.Value.team.ToLower() == "blue") ? TeamId.TEAM_BLUE : TeamId.TEAM_PURPLE), p.Value.ribbon, p.Value.icon);

                player.setName(p.Value.name);

                player.setSkinNo(p.Value.skin);
                player.userId = id; // same as StartClient.bat
                id++;

                player.setSummoners(strToId(p.Value.summoner1), strToId(p.Value.summoner2));

                Champion c   = ChampionFactory.getChampionFromType(p.Value.champion, map, GetNewNetID(), (int)player.userId);
                var      pos = c.getRespawnPosition();

                c.setPosition(pos.Item1, pos.Item2);
                c.setTeam((p.Value.team.ToLower() == "blue") ? TeamId.TEAM_BLUE : TeamId.TEAM_PURPLE);
                c.levelUp();

                player.setChampion(c);
                var pair = new Pair <uint, ClientInfo>();
                pair.Item2 = player;
                players.Add(pair);
            }

            // Uncomment the following to get 2-players

            /*ClientInfo* player2 = new ClientInfo("GOLD", TEAM_PURPLE);
             * player2->setName("tseT");
             * Champion* c2 = ChampionFactory::getChampionFromType("Ezreal", map, GetNewNetID());
             * c2->setPosition(100.f, 273.55f);
             * c2->setTeam(1);
             * map->addObject(c2);
             * player2->setChampion(c2);
             * player2->setSkinNo(4);
             * player2->userId = 2; // same as StartClient.bat
             * player2->setSummoners(SPL_Ignite, SPL_Flash);
             *
             * players.push_back(player2);*/

            return(_isAlive = true);
        }
Ejemplo n.º 29
0
        public override void die(Unit killer)
        {
            respawnTimer = 5000 + getStats().getLevel() * 2500;
            map.stopTargeting(this);

            var cKiller = killer as Champion;

            if (cKiller == null && championHitFlagTimer > 0)
            {
                cKiller = map.getObjectById(playerHitId) as Champion;
                Logger.LogCoreInfo("Killed by turret, minion or monster, but still  give gold to the enemy.");
            }

            if (cKiller == null)
            {
                PacketNotifier.notifyChampionDie(this, killer, 0);
                return;
            }

            cKiller.setChampionGoldFromMinions(0);

            float gold = map.getGoldFor(this);

            Logger.LogCoreInfo("Before: getGoldFromChamp: " + gold + " Killer:" + cKiller.killDeathCounter + "Victim: " + killDeathCounter);

            if (cKiller.killDeathCounter < 0)
            {
                cKiller.killDeathCounter = 0;
            }

            if (cKiller.killDeathCounter >= 0)
            {
                cKiller.killDeathCounter += 1;
            }

            if (killDeathCounter > 0)
            {
                killDeathCounter = 0;
            }

            if (killDeathCounter <= 0)
            {
                killDeathCounter -= 1;
            }

            if (gold > 0)
            {
                PacketNotifier.notifyChampionDie(this, cKiller, 0);
                return;
            }

            if (map.getKillReduction() && !map.getFirstBlood())
            {
                gold -= gold * 0.25f;
                //CORE_INFO("Still some minutes for full gold reward on champion kills");
            }

            if (map.getFirstBlood())
            {
                gold += 100;
                map.setFirstBlood(false);
            }

            PacketNotifier.notifyChampionDie(this, cKiller, (int)gold);

            cKiller.getStats().setGold(cKiller.getStats().getGold() + gold);
            PacketNotifier.notifyAddGold(cKiller, this, gold);

            //CORE_INFO("After: getGoldFromChamp: %f Killer: %i Victim: %i", gold, cKiller.killDeathCounter,this.killDeathCounter);

            map.stopTargeting(this);
        }
Ejemplo n.º 30
0
        public override void update(long diff)
        {
            base.update(diff);

            if (!isDead() && moveOrder == MoveOrder.MOVE_ORDER_ATTACKMOVE && targetUnit != null)
            {
                Dictionary <int, GameObject> objects = map.getObjects();
                float distanceToTarget = 9000000.0f;
                Unit  nextTarget       = null;
                float range            = Math.Max(stats.getRange(), DETECT_RANGE);

                foreach (var it in objects)
                {
                    var u = it.Value as Unit;

                    if (u == null || u.isDead() || u.getTeam() == getTeam() || distanceWith(u) > range)
                    {
                        continue;
                    }

                    if (distanceWith(u) < distanceToTarget)
                    {
                        distanceToTarget = distanceWith(u);
                        nextTarget       = u;
                    }
                }

                if (nextTarget != null)
                {
                    setTargetUnit(nextTarget);
                    PacketNotifier.notifySetTarget(this, nextTarget);
                }
            }

            if (!stats.isGeneratingGold() && map.getGameTime() >= map.getFirstGoldTime())
            {
                stats.setGeneratingGold(true);
                Logger.LogCoreInfo("Generating Gold!");
            }

            if (respawnTimer > 0)
            {
                respawnTimer -= diff;
                if (respawnTimer <= 0)
                {
                    var   spawnPos = getRespawnPosition();
                    float respawnX = spawnPos.Item1;
                    float respawnY = spawnPos.Item2;
                    setPosition(respawnX, respawnY);
                    PacketNotifier.notifyChampionRespawn(this);
                    getStats().setCurrentHealth(getStats().getMaxHealth());
                    getStats().setCurrentMana(getStats().getMaxMana());
                    deathFlag = false;
                }
            }

            bool levelup = false;

            while (getStats().getLevel() < map.getExperienceToLevelUp().Count&& getStats().getExperience() >= map.getExperienceToLevelUp()[getStats().getLevel()])
            {
                levelUp();
                levelup = true;
            }

            if (levelup)
            {
                PacketNotifier.notifyLevelUp(this);
            }

            foreach (var s in spells)
            {
                s.update(diff);
            }

            if (championHitFlagTimer > 0)
            {
                championHitFlagTimer -= diff;
                if (championHitFlagTimer <= 0)
                {
                    championHitFlagTimer = 0;
                }
            }
        }