Ejemplo n.º 1
0
        private void setCommandEvents()
        {
            foreach (var command in Commands.Where(c => c is INavigationCommand))
            {
                command.Action = () =>
                {
                    Navigated?.Invoke(this, new NavigationEventArgs(this, (command as NavigationCommand).Direction));
                };
            }

            foreach (var command in Commands.Where(c => c is IGameCommand))
            {
                command.Action = () =>
                {
                    GameMenuSelected?.Invoke(this, new GameEventArgs(this, command.Keys));
                };
            }

            foreach (var command in Commands.Where(c => c is IAttackCommand))
            {
                command.Action = () =>
                {
                    Attacked?.Invoke(this, new AttackEventArgs(this));
                };
            }
        }
Ejemplo n.º 2
0
        public API(string ip, FadeProxyClient proxy, Mode mode = Mode.BOT)
        {
            _ip = ip;

            this.mode = mode;

            // Depedency injection
            Account        = new Account(this);
            _proxy         = proxy;
            _remoteClient  = new RemoteClient(this);
            _vanillaClient = new VanillaClient(this, proxy, _remoteClient);

            Account.LoginSucceed += (s, e) => Connect();

            _vanillaClient.AuthFailed   += (s, e) => AuthFailed?.Invoke(s, e);
            _vanillaClient.Disconnected += (s, e) => Disconnected?.Invoke(s, e);
            _vanillaClient.HeroInited   += (s, e) =>
            {
                HeroInited?.Invoke(s, e);
                if (LoginTime == DateTime.MinValue)
                {
                    LoginTime = DateTime.Now;
                }
            };
            _vanillaClient.Attacked   += (s, e) => Attacked?.Invoke(s, e);
            _vanillaClient.ShipMoving += (s, e) => ShipMoving?.Invoke(s, e);
            _vanillaClient.Destroyed  += (s, e) => Destroyed?.Invoke(s, e);
        }
Ejemplo n.º 3
0
Archivo: Boss.cs Proyecto: svotoq/.Net
        public void Atack()
        {
            Attacked?.Invoke("Удар!");
            if (type == "Petya")
            {
                Console.WriteLine("Хммм.... Ошибочка! Вызовите справку!");
                return;
            }
            if (HP < 0)
            {
                Console.WriteLine("Вы пинаете мертвую тушку!");
            }
            else
            {
                if (!Agressive)
                {
                    TurnOn();
                }
                switch (Level)
                {
                case 2: Damage = 21; break;

                case 3: Damage = 8; break;
                }
                HP -= Damage;
                Console.WriteLine($"Урон {Damage}HP");
                if (HP == 70 || HP == 28)
                {
                    Upgrade();
                }
            }
        }
Ejemplo n.º 4
0
 public virtual void TakeDamage(float damage)
 {
     if (!isAlive || damage <= 0.0f)
     {
         return;
     }
     if (SupportRange.InSupportRange(gameObject))
     {
         damage *= 0.75f;
     }
     HeroUIScript.Damage(damage * (1.0f - dmgDamp * 0.01f), transform.position + Vector3.up *
                         10.0f);
     currHP -= damage * (1.0f - dmgDamp * 0.01f);
     Attacked?.Invoke();
     if (currHP <= 0.0f)
     {
         currHP  = 0.0f;
         isAlive = false;
         if (!(this is PortalInfo))
         {
             gameObject.SetActive(false);
             if (destroyable)
             {
                 Destroy(gameObject, 1.0f);
             }
         }
         Destroyed?.Invoke();
     }
 }
Ejemplo n.º 5
0
 public void OnAttacked(Ent WhoKilledMe)
 {
     Attacked?.Invoke(this, new EntEvent(box));
     if (Hp <= 0)
     {
         Die(WhoKilledMe);
     }
 }
Ejemplo n.º 6
0
 public virtual void AttackPosition(Point position, Direction attackDirection = Direction.None)
 {
     if (Attack != null)
     {
         var positionsToAttack = Attack.GetPositions(position, attackDirection == Direction.None ? Direction : attackDirection);
         Attacked?.Invoke(this, new AttackEventArgs(positionsToAttack, Attack));
     }
 }
Ejemplo n.º 7
0
        public void Attack(Character other)
        {
            var damage = calculateDamage(other);

            Attacked?.Invoke(this, new AttackEventArgs {
                Damages = damage
            });

            other.Receive(damage);
        }
Ejemplo n.º 8
0
        protected void Attack(Actor defender, uint strenght)
        {
            if (defender is null)
            {
                throw new ArgumentNullException(nameof(defender));
            }

            var ea = new AttackedEventArgs(this, defender, strenght);

            Attacked?.Invoke(this, ea);
            defender.ReceiveDamage(strenght, this);
        }
Ejemplo n.º 9
0
 public void Attack(Hero hero)
 {
     if (Weapon.Durability >= 100)
     {
         return;
     }
     hero.Defence(Weapon.Damage);
     Weapon.Using();
     Attacked?.Invoke(this, new AttackedEventArgs()
     {
         Hero = hero, Damage = CountDammage(hero, Weapon.Damage)
     });
 }
Ejemplo n.º 10
0
        public void Fight()
        {
            ApplyModifiers();
            BattleUnitsStack attacker = Subject;
            BattleUnitsStack target   = Object;

            attacker.AttackStack(target);
            Attacked?.Invoke();
            if (target.canRetaliate)
            {
                target.AttackStack(attacker);
            }
            target.canRetaliate = false;
            Revenged?.Invoke();
        }
Ejemplo n.º 11
0
 public void Attack(Hero hero)
 {
     if (Weapon.Durability < 100)
     {
         int damage = hero.TakeDamege(Weapon.Damage);
         Weapon.Using();
         Attacked?.Invoke(this, new AttakedEventArgs()
         {
             Hero = hero, AttakedHp = damage
         });
     }
     else
     {
         Console.WriteLine("Оружие сломалось");
     }
 }
Ejemplo n.º 12
0
    public void Attack(float multiplier, bool isPerfect)
    {
        var target = Cameraer.Instance.GetTargetPosition();

        transform.LookAt(new Vector3(target.x, transform.position.y, target.z));
        var args = new AttackArgs()
        {
            Position   = transform.position,
            Rotation   = transform.rotation,
            Multiplier = multiplier,
            IsPerfect  = isPerfect
        };

        Attacks.Execute(AttackType, args, false);
        Attacked?.Invoke(this, new AttackedArgs(AttackType, args));
    }
Ejemplo n.º 13
0
        public void Update(TimeSpan deltaTime)
        {
            var playerDistance = Vector2.Distance(mGame.Player.Position, Position);

            if (playerDistance > DetectionRange)
            {
                if (mTurnCooldown.Elapsed.TotalSeconds > 5)
                {
                    var angle = UnityEngine.Random.Range(0, Mathf.PI * 2);
                    Direction     = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
                    mTurnCooldown = Stopwatch.StartNew();
                }
            }
            else
            {
                if (playerDistance > AttackRange.Value)
                {
                    Direction = mGame.Player.Position - Position;
                    Direction.Normalize();
                }
                else
                {
                    Direction = Vector2.zero;
                    if (mAttackCooldown.Elapsed.TotalSeconds >= 1 / AttackRate.Value)
                    {
                        mGame.Attack(this, mGame.Player);
                        mAttackCooldown = Stopwatch.StartNew();
                        Attacked?.Invoke(this, EventArgs.Empty);
                    }
                }
            }

            var dir = Direction;

            if (dir != Vector2.zero)
            {
                dir.Normalize();
                var newPos   = Position + dir * Speed.Value * (float)deltaTime.TotalSeconds;
                var collided = mGame.CheckMonsterCollision(new Rect(newPos, Size), this);
                collided = MathUtils.Collide(collided, mGame.Player.Bounds);
                collided = mGame.Map.CheckCollision(collided);
                Position = new Vector2(collided.xMin, collided.yMin);
            }
        }
Ejemplo n.º 14
0
        public override void Parse(EndianBinaryReader reader)
        {
            ushort length;
            ushort id;

            byte[] content;

            if (!IsConnected() || tcpClient.Available == 0)
            {
                return;
            }

            var lengthBuffer = reader.ReadBytes(2);

            lengthBuffer = _proxy.Decrypt(lengthBuffer);
            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(lengthBuffer);
            }
            length = BitConverter.ToUInt16(lengthBuffer, 0);

            if (!IsConnected())
            {
                return;
            }

            content = _proxy.Decrypt(reader.ReadBytes(length));

            EndianBinaryReader cachedReader = new EndianBinaryReader(EndianBitConverter.Big, new MemoryStream(content));

            id = cachedReader.ReadUInt16();

            Console.WriteLine($"Received: {id}");

            switch (id)
            {
            case ServerVersionCheck.ID:
                ServerVersionCheck serverVersionCheck = new ServerVersionCheck(cachedReader);

                if (serverVersionCheck.compatible)
                {
                    Compatible?.Invoke(this, EventArgs.Empty);
                    Send(new ClientRequestCode());
                }
                else
                {
                    NotCompatible?.Invoke(this, EventArgs.Empty);
                    thread.Abort();
                }
                break;

            case ServerRequestCode.ID:
                ServerRequestCode serverRequestCode = new ServerRequestCode(cachedReader);
                Generator         generator         = new Generator();
                generator.Build(serverRequestCode.code);
                _proxy.InitStageOne(generator.Output);
                break;

            case ServerRequestCallback.ID:
                Console.WriteLine("Stage two received");
                ServerRequestCallback serverRequestCallback = new ServerRequestCallback(cachedReader);

                _proxy.InitStageTwo(serverRequestCallback.secretKey);

                Console.WriteLine("StageTwo initialized");

                Console.WriteLine("Sending login request");

                SendEncoded(new Ping());
                SendEncoded(new Login(api.Account.UserID, api.Account.SID, 0, api.Account.InstanceID));
                SendEncoded(new Ready());
                break;

            case BuildingInit.ID:
                BuildingInit buildingInit = new BuildingInit(cachedReader);
                lock (api.buildingsLocker)
                    api.Buildings.Add(new Building(buildingInit.BuildingID, buildingInit.Name, buildingInit.X, buildingInit.Y, buildingInit.AssetType));
                break;

            case DestroyBuilding.ID:
                DestroyBuilding destroyBuilding = new DestroyBuilding(cachedReader);
                lock (api.buildingsLocker)
                    api.Buildings.RemoveAll(building => building.BuildingID == destroyBuilding.BuildingID);
                break;

            case GateInit.ID:
                GateInit gateInit = new GateInit(cachedReader);
                api.Gates.Add(new Gate(gateInit.GateType, gateInit.X, gateInit.Y));
                break;

            case ShipDestroyed.ID:
                ShipDestroyed shipDestroyed = new ShipDestroyed(cachedReader);
                if (shipDestroyed.UserID == api.Account.UserID)
                {
                    Destroyed?.Invoke(this, EventArgs.Empty);
                }
                break;

            case Notify.ID:
                Notify notify = new Notify(cachedReader);
                if (notify.MessageType == "ttip_killscreen_basic_repair")
                {
                    Destroyed?.Invoke(this, EventArgs.Empty);
                }
                break;

            case MapChanged.ID:
                MapChanged mapChanged = new MapChanged(cachedReader);
                Console.WriteLine($"Map changed to: {mapChanged.MapID} | {mapChanged.var_294}");
                SendEncoded(new MapChangeConfirmation(true));
                break;

            case HeroInit.ID:
                HeroInit heroInit = new HeroInit(cachedReader);

                api.Boxes.Clear();
                api.MemorizedBoxes.Clear();
                api.Ores.Clear();
                api.Ships.Clear();
                api.Gates.Clear();
                api.Buildings.Clear();

                // Movement
                api.Account.X = heroInit.X;
                api.Account.Y = heroInit.Y;

                // Map statistics
                api.Account.HP             = (int)heroInit.HP;
                api.Account.MaxHP          = (int)heroInit.MaxHP;
                api.Account.Shield         = (int)heroInit.Shield;
                api.Account.MaxShield      = (int)heroInit.MaxShield;
                api.Account.NanoHP         = (int)heroInit.NanoHP;
                api.Account.MaxNanoHP      = (int)heroInit.MaxNanoHP;
                api.Account.FreeCargoSpace = (int)heroInit.FreeCargoSpace;
                api.Account.CargoCapacity  = (int)heroInit.CargoCapacity;

                // Ship
                api.Account.Shipname = heroInit.Shipname;
                api.Account.Speed    = (int)(heroInit.Speed * 0.97);

                // Statistics
                api.Account.Cloaked = heroInit.Cloaked;
                api.Account.Jackpot = heroInit.Jackpot;
                api.Account.Premium = heroInit.Premium;
                api.Account.Credits = heroInit.Credits;
                api.Account.Honor   = heroInit.Honor;
                api.Account.Uridium = heroInit.Uridium;
                api.Account.XP      = heroInit.XP;
                api.Account.Level   = (int)heroInit.Level;
                api.Account.Rank    = (int)heroInit.Rank;

                // Social
                api.Account.ClanID    = (int)heroInit.ClanID;
                api.Account.ClanTag   = heroInit.ClanTag;
                api.Account.FactionID = heroInit.FactionID;

                HeroInited?.Invoke(this, EventArgs.Empty);
                api.Account.Ready = true;
                Task.Delay(15000).ContinueWith(_ => api.Account.JumpAllowed = true);

                SendEncoded(new InitPacket(1));
                SendEncoded(new InitPacket(2));
                break;

            case 24328:     //CpuInitializationCommand
                SendEncoded(new OldStylePacket("JCPU|GET"));
                break;

            case DroneFormationUpdated.ID:
                DroneFormationUpdated droneFormationUpdated = new DroneFormationUpdated(cachedReader);
                break;

            case ShipUpdated.ID:
                ShipUpdated shipUpdated = new ShipUpdated(cachedReader);
                api.Account.UpdateHitpointsAndShield(shipUpdated.HP, shipUpdated.Shield, shipUpdated.NanoHP);
                break;

            case ShieldUpdated.ID:
                ShieldUpdated shieldUpdated = new ShieldUpdated(cachedReader);
                api.Account.UpdateShield(shieldUpdated.Shield, shieldUpdated.MaxShield);
                break;

            case CargoUpdated.ID:
                CargoUpdated cargoUpdated = new CargoUpdated(cachedReader);
                api.Account.FreeCargoSpace = api.Account.CargoCapacity - (int)cargoUpdated.CargoCount;
                break;

            case HitpointsUpdated.ID:
                HitpointsUpdated hitpointsUpdated = new HitpointsUpdated(cachedReader);
                api.Account.UpdateHitpoints(hitpointsUpdated.HP, hitpointsUpdated.MaxHP, hitpointsUpdated.NanoHP, hitpointsUpdated.MaxNanoHP);
                break;

            case ShipAttacked.ID:
                ShipAttacked shipAttacked = new ShipAttacked(cachedReader);
                Attacked?.Invoke(this, shipAttacked);
                break;

            case ShipInit.ID:
                ShipInit shipInit = new ShipInit(cachedReader);
                Ship     newShip  = new Ship();
                newShip.UserID   = (int)shipInit.UserID;
                newShip.Username = shipInit.Username;
                newShip.NPC      = shipInit.NPC;

                // Movement
                newShip.X = shipInit.X;
                newShip.Y = shipInit.Y;

                // Ship
                newShip.Shipname = shipInit.Shipname;

                // Statistics
                newShip.Cloaked = shipInit.Cloaked;

                // Social
                newShip.ClanID    = (int)shipInit.ClanID;
                newShip.ClanTag   = shipInit.ClanTag;
                newShip.FactionID = (int)shipInit.FactionID;
                lock (api.shipsLocker)
                    api.Ships.Add(newShip);
                break;

            case ShipMove.ID:
                ShipMove shipMove = new ShipMove(cachedReader);
                ShipMoving?.Invoke(this, shipMove);
                break;

            case BoxInit.ID:
                BoxInit boxInit = new BoxInit(cachedReader);
                if (boxInit.Hash.Length != 5)
                {
                    Box box = new Box(boxInit.Hash, boxInit.X, boxInit.Y, boxInit.Type);
                    lock (api.boxesLocker) lock (api.memorizedBoxesLocker)
                        {
                            api.Boxes.Add(box);
                            api.MemorizedBoxes.Add(box);
                        }
                }
                break;

            case DestroyItem.ID:
                DestroyItem item = new DestroyItem(cachedReader);
                lock (api.boxesLocker) lock (api.memorizedBoxesLocker)
                    {
                        api.Boxes.RemoveAll(box => box.Hash == item.Hash);
                        if (item.CollectedByPlayer)
                        {
                            api.MemorizedBoxes.RemoveAll(box => box.Hash == item.Hash);
                        }
                    }
                lock (api.oresLocker)
                    api.Ores.RemoveAll(ore => ore.Hash == item.Hash);
                break;

            case DestroyShip.ID:
                DestroyShip destroyedShip = new DestroyShip(cachedReader);
                lock (api.Ships)
                    api.Ships.RemoveAll(ship => ship.UserID == destroyedShip.UserID);
                break;

            case OreInit.ID:
                OreInit oreInit = new OreInit(cachedReader);
                lock (api.oresLocker)
                    api.Ores.Add(new Ore(oreInit.Hash, oreInit.X, oreInit.Y, oreInit.Type));
                break;

            case 17162:
                if (!pingThread.IsAlive)
                {
                    pingThread = new Thread(new ThreadStart(PingLoop));
                    pingThread.Start();
                }
                break;

            case OldStylePacket.ID:
                OldStylePacket oldStylePacket  = new OldStylePacket(cachedReader);
                string[]       splittedMessage = oldStylePacket.Message.Split('|');
                switch (splittedMessage[1])
                {
                case OldPackets.SELECT:
                    switch (splittedMessage[2])
                    {
                    case OldPackets.CONFIG:
                        api.Account.Config = Convert.ToInt32(splittedMessage[3]);
                        break;
                    }
                    break;

                case OldPackets.PORTAL_JUMP:
                    Console.WriteLine($"(Old) Map changed to: {splittedMessage[2]}");
                    SendEncoded(new MapChangeConfirmation(true));
                    break;

                case OldPackets.LOG_MESSAGE:
                    switch (splittedMessage[3])
                    {
                    case OldPackets.BOX_CONTENT_CREDITS:
                        api.Account.CollectedCredits += double.Parse(splittedMessage[4]);
                        break;

                    case OldPackets.BOX_CONTENT_URIDIUM:
                        api.Account.CollectedUridium += double.Parse(splittedMessage[4]);
                        break;

                    case OldPackets.BOX_CONTENT_EE:
                        api.Account.CollectedEE += int.Parse(splittedMessage[4]);
                        break;

                    case OldPackets.BOX_CONTENT_XP:
                        api.Account.CollectedXP += double.Parse(splittedMessage[4]);
                        break;

                    case OldPackets.BOX_CONTENT_HON:
                        api.Account.CollectedHonor += double.Parse(splittedMessage[4]);
                        break;
                    }
                    LogMessage?.Invoke(this, string.Join("|", splittedMessage));
                    break;

                default:
                    Console.WriteLine("Received unsupported old style packet with message: {0}", oldStylePacket.Message);
                    break;
                }
                break;

            default:
                Console.WriteLine("Received packet of ID {0} with total size of {1} which is not supported", id, length + 4);
                break;
            }
        }
Ejemplo n.º 15
0
 public void OnAttack()
 {
     Console.WriteLine($"King {Name} is under attack!");
     Attacked?.Invoke();
 }
Ejemplo n.º 16
0
 public void Attack(ICreature enemy)
 {
     enemy.AcceptDamage(Damage);
     Attacked?.Invoke(this);
 }
Ejemplo n.º 17
0
 protected virtual void OnAttacked()
 {
     Attacked?.Invoke();
 }
Ejemplo n.º 18
0
 /// <summary>
 /// 受到攻击的时候调用,可以被复写
 /// </summary>
 /// <param name="from"></param>
 /// <param name="dam"></param>
 public virtual void UnderAttack(LivingEntity from, DamageClass dam)
 {
     Attacked?.Invoke(from, dam);
     Health -= dam.Damage;
 }
Ejemplo n.º 19
0
 protected virtual void OnAttacked(Creature attackingCreature)
 {
     Attacked?.Invoke(this, attackingCreature);
 }
Ejemplo n.º 20
0
 public void OnAttacked(DoneEventArgs Args)
 {
     Attacked?.Invoke(this, Args);
 }
Ejemplo n.º 21
0
 /*----- Events Methodes -----*/
 protected virtual void OnAttacked(AFighter target)
 {
     Attacked?.Invoke(this, target);
 }
Ejemplo n.º 22
0
 protected virtual void OnAttacked(DrawableMiniBoss drawableMiniBoss, double timeOffset) => Attacked?.Invoke(drawableMiniBoss, timeOffset);
Ejemplo n.º 23
0
 protected void OnAttacked(AttackerableEventArgs e) => Attacked?.Invoke(this, e);