Esempio n. 1
0
        public bool RemoveInRangeCharacter(Character character)
        {
            try
            {
                if (character.Spacemap != Spacemap || !InRangeCharacters.ContainsKey(character.Id))
                {
                    return(false);
                }

                var success = InRangeCharacters.TryRemove(character.Id, out character);
                if (success)
                {
                    InRangeCharacterRemoved?.Invoke(this, new CharacterArgs(character));

                    if (Selected == character)
                    {
                        Deselection();
                    }

                    if (this is Player player)
                    {
                        player.SendCommand(ShipRemoveCommand.write(character.Id));
                    }
                }
                return(success);
            }
            catch (Exception e)
            {
                Out.WriteLine("RemoveInRangeCharacter void exception " + e, "Character.cs");
                Logger.Log("error_log", $"- [Character.cs] RemoveInRangeCharacter void exception: {e}");
                return(false);
            }
        }
Esempio n. 2
0
        public void Deactivate(bool direct = false, bool destroyed = false)
        {
            if (Activated)
            {
                if (LastCombatTime.AddSeconds(10) < DateTime.Now || direct)
                {
                    if (destroyed)
                    {
                        Owner.SendPacket("0|A|STM|msg_pet_is_dead");
                        CurrentHitPoints    = 1000;
                        CurrentShieldPoints = 0;
                        UpdateStatus();
                    }
                    else
                    {
                        Owner.SendPacket("0|A|STM|msg_pet_deactivated");
                    }

                    Owner.SendPacket("0|PET|D");
                    Activated = false;

                    InRangeCharacters.Clear();
                    Spacemap.RemoveCharacter(this);
                    Program.TickManager.RemoveTick(this);
                }
                else
                {
                    Owner.SendPacket("0|A|STM|msg_pet_in_combat");
                }
            }
        }
Esempio n. 3
0
        public void Deactivate(bool direct = false, bool destroyed = false)
        {
            if (Activated)
            {
                if (LastCombatTime.AddSeconds(10) < DateTime.Now || direct)
                {
                    Owner.SendPacket("0|PET|D");

                    if (destroyed)
                    {
                        Owner.Settings.InGameSettings.petDestroyed = true;
                        QueryManager.SavePlayer.Settings(Owner, "inGameSettings", Owner.Settings.InGameSettings);

                        Owner.SendPacket("0|PET|Z");
                        CurrentShieldPoints = 0;
                        UpdateStatus();

                        Owner.SendCommand(PetInitializationCommand.write(true, true, false));
                        Owner.SendCommand(PetUIRepairButtonCommand.write(true, 250));
                    }
                    else
                    {
                        Owner.SendPacket("0|A|STM|msg_pet_deactivated");
                    }

                    Activated = false;

                    Deselection();
                    Spacemap.RemoveCharacter(this);
                    InRangeCharacters.Clear();
                    Program.TickManager.RemoveTick(this);
                }
                else
                {
                    Owner.SendPacket("0|A|STM|msg_pet_in_combat");
                }
            }
        }
Esempio n. 4
0
        public bool AddInRangeCharacter(Character character)
        {
            try
            {
                if (character == null || InRangeCharacters.ContainsKey(character.Id) || character.Destroyed || character.Id == Id || character.Spacemap.Id != Spacemap.Id)
                {
                    return(false);
                }

                var success = InRangeCharacters.TryAdd(character.Id, character);

                if (success)
                {
                    InRangeCharacterAdded?.Invoke(this, new CharacterArgs(character));

                    if (this is Player player)
                    {
                        short relationType = character.Clan.Id != 0 && Clan.Id != 0 ? Clan.GetRelation(character.Clan) : (short)0;

                        if (character is Player)
                        {
                            var otherPlayer = character as Player;
                            player.SendCommand(otherPlayer.GetShipCreateCommand(player, relationType));

                            if (otherPlayer.Title != "" && !EventManager.JackpotBattle.InEvent(otherPlayer))
                            {
                                player.SendPacket($"0|n|t|{otherPlayer.Id}|1|{otherPlayer.Title}");
                            }

                            player.SendPacket(otherPlayer.DroneManager.GetDronesPacket());
                            player.SendCommand(DroneFormationChangeCommand.write(otherPlayer.Id, DroneManager.GetSelectedFormationId(otherPlayer.Settings.InGameSettings.selectedFormation)));
                        }
                        else if (character is Pet)
                        {
                            var pet = character as Pet;
                            if (pet == player.Pet)
                            {
                                player.SendCommand(PetHeroActivationCommand.write(pet.Owner.Id, pet.Id, 22, 3, pet.Name, (short)pet.Owner.FactionId, pet.Owner.Clan.Id, 15, pet.Owner.Clan.Tag, pet.Position.X, pet.Position.Y, pet.Speed, new class_11d(class_11d.DEFAULT)));
                            }
                            else
                            {
                                player.SendCommand(PetActivationCommand.write(pet.Owner.Id, pet.Id, 22, 3, pet.Name, (short)pet.Owner.FactionId, pet.Owner.Clan.Id, 15, pet.Owner.Clan.Tag, new ClanRelationModule(relationType), pet.Position.X, pet.Position.Y, pet.Speed, false, true, new class_11d(class_11d.DEFAULT)));
                            }
                        }
                        else
                        {
                            player.SendCommand(character.GetShipCreateCommand());
                        }

                        var timeElapsed = (DateTime.Now - character.MovementStartTime).TotalMilliseconds;
                        player.SendCommand(MoveCommand.write(character.Id, character.Destination.X, character.Destination.Y, (int)(character.MovementTime - timeElapsed)));
                    }
                }

                return(success);
            }
            catch (Exception e)
            {
                Out.WriteLine("AddInRangeCharacter void exception " + e, "Character.cs");
                Logger.Log("error_log", $"- [Character.cs] AddInRangeCharacter void exception: {e}");
                return(false);
            }
        }