Example #1
0
        public bool playerDeath(Player victim, Player killer, Helpers.KillType killType, CS_VehicleDeath update)
        {
            //Was it a player kill?
            if (killType == Helpers.KillType.Player)
            {   //No team killing!
                if (victim._team != killer._team)
                {
                    //Does the killer have an HQ?
                    if (_hqs[killer._team] != null)
                    {
                        //Reward his HQ! (Victims bounty + half of own)
                        _hqs[killer._team].Bounty += victim.Bounty + (killer.Bounty / 2);
                    }
                }
            }

            //Was it a computer kill?
            if (killType == Helpers.KillType.Computer)
            {
                //Let's find the vehicle!
                Computer cvehicle  = victim._arena.Vehicles.FirstOrDefault(v => v._id == update.killerPlayerID) as Computer;
                Player   vehKiller = cvehicle._creator;
                //Do they exist?
                if (cvehicle != null && vehKiller != null)
                {   //We'll take it from here...
                    update.type           = Helpers.KillType.Player;
                    update.killerPlayerID = vehKiller._id;

                    //Don't reward for teamkills
                    if (vehKiller._team == victim._team)
                    {
                        Logic_Assets.RunEvent(vehKiller, _arena._server._zoneConfig.EventInfo.killedTeam);
                    }
                    else
                    {
                        Logic_Assets.RunEvent(vehKiller, _arena._server._zoneConfig.EventInfo.killedEnemy);
                    }

                    //Increase stats/HQ bounty and notify arena of the kill!
                    if (_hqs[vehKiller._team] != null)
                    {
                        //Reward his HQ! (Victims bounty + half of own)
                        _hqs[vehKiller._team].Bounty += victim.Bounty + (vehKiller.Bounty / 2);
                    }

                    vehKiller.Kills++;
                    victim.Deaths++;
                    Logic_Rewards.calculatePlayerKillRewards(victim, vehKiller, update);
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
        public static bool joinTeam(this Player player, Team team)
        {
            //Sanity checks
            if (player._occupiedVehicle == null)
            {
                Log.write(TLog.Warning, "Attempted to unspectate with no spectator vehicle. {0}", player);
                return(false);
            }

            //Make sure our vehicle is a spectator mode vehicle
            if (player._occupiedVehicle._type.Type != VehInfo.Types.Spectator)
            {
                Log.write(TLog.Warning, "Attempted to unspectate with non-spectator vehicle. {0}", player);
                return(false);
            }

            //Reset leftover variables
            player._deathTime     = 0;
            player._lastMovement  = Environment.TickCount;
            player._maxTimeCalled = false;

            //Throw ourselves onto our new team!
            team.addPlayer(player);

            //Destroy our spectator vehicle
            player._occupiedVehicle.destroy(true);
            player._bSpectator = false;

            //Set relative vehicle if required, no need for any if statement here :]
            VehInfo vehicle = player._server._assets.getVehicleByID(player.getDefaultVehicle().Id + player._server._zoneConfig.teams[team._id].relativeVehicle);

            player.setDefaultVehicle(vehicle);

            //Run the exit spec event
            Logic_Assets.RunEvent(player, player._server._zoneConfig.EventInfo.exitSpectatorMode);

            //Make sure the arena knows we've entered
            player._arena.playerEnter(player);

            if (player.ZoneStat1 > player._server._zoneConfig.bounty.start)
            {
                player.Bounty = player.ZoneStat1;
            }
            else
            {
                player.Bounty = player._server._zoneConfig.bounty.start;
            }

            return(true);
        }
Example #3
0
        /// <summary>
        /// Adds the given player to the team and notifies others
        /// </summary>
        public void addPlayer(Player player, bool manualJoin)
        {       //Sanity checks
            if (player._bIngame && player._team == this)
            {
                Log.write(TLog.Warning, "Attempted to add player to his own team. {0}", player);
                return;
            }

            //Have him lose his current team
            if (player._team != null)
            {
                player._team.lostPlayer(player);
            }

            //Set his new team!
            player._team = this;

            //Welcome him in
            if (!_players.Contains(player))
            {
                _players.Add(player);
            }

            //Do we need to notify, or is this an initial team?
            if (player._bIngame)
            {
                //Let everyone know
                Helpers.Player_SetTeam(_arena.Players, player, this);
            }

            player.sendMessage(0, "Team joined: " + _name);

            //Set relative vehicle if required, no need for any if statement here :]
            VehInfo vehicle = _server._assets.getVehicleByID(player.getDefaultVehicle().Id + _relativeVehicle);

            player.setDefaultVehicle(vehicle);

            //If he isn't a spectator, trigger the event too
            if (!player.IsSpectator)
            {
                if (manualJoin)
                {
                    Logic_Assets.RunEvent(player, _server._zoneConfig.EventInfo.manualJoinTeam);
                }
                else
                {
                    Logic_Assets.RunEvent(player, _server._zoneConfig.EventInfo.joinTeam);
                }
            }
        }
        public bool playerDeath(Player victim, Player killer, Helpers.KillType killType, CS_VehicleDeath update)
        {
            //Respawn flag where it was initially spawn if a marine died carrying one
            try
            {
                _arena.flagResetPlayer(victim);
            }
            catch (Exception e)
            {
                Log.write(TLog.Exception, "exception in flagResetPlayer(victim):: '{0}'", e);
            }
            //Was it a computer kill?
            if (killType == Helpers.KillType.Computer)
            {
                //Let's find the vehicle!
                Computer cvehicle  = victim._arena.Vehicles.FirstOrDefault(v => v._id == update.killerPlayerID) as Computer;
                Player   vehKiller = cvehicle._creator;
                //Does it exist?
                if (cvehicle != null && vehKiller != null)
                {
                    //We'll take it from here...
                    update.type           = Helpers.KillType.Player;
                    update.killerPlayerID = vehKiller._id;

                    //Don't reward for teamkills
                    if (vehKiller._team == victim._team)
                    {
                        Logic_Assets.RunEvent(vehKiller, _arena._server._zoneConfig.EventInfo.killedTeam);
                    }
                    else
                    {
                        Logic_Assets.RunEvent(vehKiller, _arena._server._zoneConfig.EventInfo.killedEnemy);
                    }

                    //Increase stats and notify arena of the kill!
                    vehKiller.Kills++;
                    victim.Deaths++;
                    Logic_Rewards.calculatePlayerKillRewards(victim, vehKiller, update);
                    return(false);
                }
            }
            return(true);
        }
Example #5
0
        public bool playerDeath(Player victim, Player killer, Helpers.KillType killType, CS_VehicleDeath update)
        {
            if (killer == null)
            {
                return(true);
            }

            //Was it a player kill?
            if (killType == Helpers.KillType.Player)
            {   //No team killing!
                if (victim._team != killer._team)
                {
                    //Does the killer have an HQ?
                    if (_hqs[killer._team] != null)
                    {
                        //Reward his HQ! (Victims bounty + half of own)
                        _hqs[killer._team].Bounty += victim.Bounty + (killer.Bounty / 2);
                    }
                }

                //Find out if KOTH is running
                if (_activeCrowns.Count == 0 || killer == null)
                {
                    return(true);
                }

                //Handle crowns
                if (_playerCrownStatus.ContainsKey(victim) && _playerCrownStatus[victim].crown)
                {   //Incr crownDeaths
                    _playerCrownStatus[victim].crownDeaths++;

                    if (_playerCrownStatus[victim].crownDeaths >= _config.king.deathCount)
                    {
                        //Take it away now
                        _playerCrownStatus[victim].crown = false;
                        _noCrowns.Remove(victim);
                        Helpers.Player_Crowns(_arena, false, _noCrowns);
                    }
                    if (_playerCrownStatus.ContainsKey(killer))
                    {
                        if (!_playerCrownStatus[killer].crown)
                        {
                            _playerCrownStatus[killer].crownKills++;
                        }
                    }
                }

                //Reset their timer
                if (_playerCrownStatus.ContainsKey(killer))
                {
                    if (_playerCrownStatus[killer].crown)
                    {
                        updateCrownTime(killer);
                    }
                    else if (_config.king.crownRecoverKills != 0)
                    {   //Should they get a crown?
                        if (_playerCrownStatus[killer].crownKills >= _config.king.crownRecoverKills)
                        {
                            _playerCrownStatus[killer].crown = true;
                            giveCrown(killer);
                        }
                    }
                }
            }

            //Was it a computer kill?
            if (killType == Helpers.KillType.Computer)
            {
                //Let's find the vehicle!
                Computer cvehicle  = victim._arena.Vehicles.FirstOrDefault(v => v._id == update.killerPlayerID) as Computer;
                Player   vehKiller = cvehicle._creator;
                //Do they exist?
                if (cvehicle != null && vehKiller != null)
                {   //We'll take it from here...
                    update.type           = Helpers.KillType.Player;
                    update.killerPlayerID = vehKiller._id;

                    //Don't reward for teamkills
                    if (vehKiller._team == victim._team)
                    {
                        Logic_Assets.RunEvent(vehKiller, _arena._server._zoneConfig.EventInfo.killedTeam);
                    }
                    else
                    {
                        Logic_Assets.RunEvent(vehKiller, _arena._server._zoneConfig.EventInfo.killedEnemy);
                    }

                    //Increase stats/HQ bounty and notify arena of the kill!
                    if (_hqs[vehKiller._team] != null)
                    {
                        //Reward his HQ! (Victims bounty + half of own)
                        _hqs[vehKiller._team].Bounty += victim.Bounty + (vehKiller.Bounty / 2);
                    }

                    vehKiller.Kills++;
                    victim.Deaths++;
                    Logic_Rewards.calculatePlayerKillRewards(victim, vehKiller, update);
                    return(false);
                }
            }
            return(true);
        }
Example #6
0
        /// <summary>
        /// Called when a new player is entering our arena
        /// </summary>
        public void newPlayer(Player player)
        {       ///////////////////////////////////////////////
            // Prepare the player state
            ///////////////////////////////////////////////

            //We're entering the arena..
            player._arena = this;

            RecallPlayerStats(player);
            player.resetVars();

            player._ipAddress = player._client._ipe.Address;

            //TODO: Check rules for whether player enters in spec
            //_server._zoneConfig.arena.startInSpectator
            player._bSpectator = true;
            player._team       = _teams["spec"];

            //Find his natural vehicle id and prepare the class
            Player.SkillItem baseSkill = player._skills.Values.FirstOrDefault(skill => skill.skill.DefaultVehicleId != -1);
            int     baseVehicleID      = (baseSkill == null) ? _server._zoneConfig.publicProfile.defaultVItemId : baseSkill.skill.DefaultVehicleId;
            Vehicle baseVehicle        = new Vehicle(_server._assets.getVehicleByID(baseVehicleID), this);

            baseVehicle._bBaseVehicle = true;
            baseVehicle._id           = player._id;
            baseVehicle._state        = player._state;  //Player and basevehicle share same state

            player._baseVehicle = baseVehicle;

            //Run the initial events
            if (_server.IsStandalone)
            {
                player.firstTimeEvents();
            }

            if (player.firstTimePlayer)
            {
                Logic_Assets.RunEvent(player, _server._zoneConfig.EventInfo.firstTimeSkillSetup);
                Logic_Assets.RunEvent(player, _server._zoneConfig.EventInfo.firstTimeInvSetup);
                if (player._bIngame)
                {
                    player.firstTimePlayer = false;
                }
            }

            //Create our new spam filter list
            player._msgTimeStamps = new List <DateTime>();

            ///////////////////////////////////////////////
            // Send the player state
            ///////////////////////////////////////////////
            //Make sure he's receiving ingame packets
            player._client.sendReliable(new SC_SetIngame());

            //Add him to our list of players. We want to do this now so he doesn't lose
            //info about anything happening until then.
            if (!_players.Contains(player))
            {
                _players.Add(player);
            }

            //Check his processes quick
            SC_Environment env = new SC_Environment();

            env.bLimitLength = false;
            player._client.sendReliable(env);

            //Lets check his level and set watchMod
            if (player.PermissionLevel >= Data.PlayerPermission.ArenaMod)
            {
                player._watchMod = true;
            }

            //Check if we can use him as a reliable player [check if mod]
            if (player.PermissionLevel >= Data.PlayerPermission.ArenaMod)
            {
                player.setVar("reliable", player);
            }

            //Send a security check for their client asset checksum
            SC_SecurityCheck cs = new SC_SecurityCheck();

            cs.key     = 1015;       //Key we are using
            cs.unknown = 0;          // Unknown, send as 0
            player._client.send(cs); //Send it

            //Define the player's self object
            Helpers.Object_Players(player, player);

            //Make sure the player is aware of every player in the arena
            List <Player> audience = Players.ToList();

            //Check first for stealthed mods
            //Note: this is for any other players joining while there is a stealthed mod
            foreach (Player p in audience)
            {
                //Check their levels with the players level
                if (p != player)
                {
                    if (!p.IsStealth)
                    {
                        Helpers.Object_Players(player, p);
                    }
                    if (p.IsStealth && player.PermissionLevel >= p.PermissionLevel)
                    {
                        Helpers.Object_Players(player, p);
                    }
                }
            }

            //Load the arena's item state
            Helpers.Object_Items(player, _items.Values);

            //Load the arena's various lio objects
            Helpers.Object_Flags(player, _flags.Values);
            Helpers.Object_LIOs(player, _switches.Values);

            //Load the vehicles in the arena
            if (_vehicles.Count > 0)
            {
                Helpers.Object_Vehicles(player, _vehicles);
            }

            //Load the ball state if any
            if (_balls.Count > 0)
            {
                Helpers.Object_Ball(player, _balls);
            }

            //Suspend his stats if it's a private arena
            if (_bIsPublic)
            {
                player.restoreStats();
                player.suspendCalled = false;
            }
            else if (!player.suspendCalled)
            {
                player.suspendStats();
                player.suspendCalled = true;
            }

            //Is this a private arena and are we the first one?
            if (!player._arena._name.StartsWith("Public", StringComparison.OrdinalIgnoreCase) && player._arena.TotalPlayerCount == 1)
            {
                //Give player required privileges
                player._arena._owner.Add(player._alias);
                if (player.PermissionLevel < Data.PlayerPermission.ArenaMod)
                {
                    player._permissionTemp = Data.PlayerPermission.ArenaMod;
                    player._watchMod       = true;
                }
            }

            //Are we zone silenced or arena silenced?
            if (!this._server._playerSilenced.ContainsKey(player._ipAddress))
            {   //Since we are not in the zone list, check the arena list
                if (!this._silencedPlayers.ContainsKey(player._alias))
                {
                    player._bSilenced = false;
                }
                else
                {
                    player._bSilenced = true;
                }
            }

            //Initialize the player's state
            Helpers.Player_StateInit(player,
                                     delegate()
            {
                //Check for stealthing/cloaking mods first
                //Note: this is for the stealthed person entering
                if (!player.IsStealth)
                {
                    //Make sure everyone is aware of him
                    Helpers.Object_Players(audience, player);
                }
                else
                {     //Check their level vs people in the room
                    foreach (Player person in audience)
                    {
                        //Their level is the same or greater, allow them to see him/her
                        if (person != player && person.PermissionLevel >= player.PermissionLevel)
                        {
                            Helpers.Object_Players(person, player);
                        }
                    }
                }

                //Consider him loaded!
                player.spec();
                player.setIngame();

                //Load the tickers
                Helpers.Arena_Message(player, _tickers.Values);

                //Load all the banners
                Helpers.Social_UpdateBanner(player);                        //Players banner
                Helpers.Social_ArenaBanners(player._arena.Players, player); //Inform arena of his banner
                Helpers.Social_ArenaBanners(player, this);                  //Get all banners in arena
                //Set able to receive banners
                player._bAllowBanner = true;

                //Trigger our event for player entering arena
                callsync("Player.EnterArena", false, player);

                //Temporary player message, remove this later. This is just here to get old accounts to update their information
                player.sendMessage(-3, "[Notice] Welcome to Infantry! To get support simply use the discord link located on the top right of the infantry launcher. Enjoy your stay!");

                //Mod notice
                if (player.PermissionLevelLocal >= Data.PlayerPermission.ArenaMod && !player._arena.IsPrivate)
                {
                    player.sendMessage(-3, "$[Mod Notice] To see a list of commands, type *help. To specifically get info on a command type *help <command name>");
                }
            }
                                     );
        }
Example #7
0
        /// <summary>
        /// Attempts to allow a player to use a computer vehicle to produce
        /// </summary>
        public bool produceRequest(Player player, Computer computer, VehInfo.Computer.ComputerProduct product)
        {       //Is the player able to use this production item?
            if (!Logic_Assets.SkillCheck(player, product.SkillLogic))
            {   //The client should prevent this, so let's warn
                Log.write(TLog.Warning, "Player {0} attempted to use vehicle ({1}) produce without necessary skills.", player._alias, computer._type.Name);
                return(false);
            }

            //Do we have everything needed?
            if (player.Cash < product.Cost)
            {
                player.sendMessage(-1, "You do not have enough cash to produce this item.");
                return(false);
            }

            //Are we able to produce in parallel?
            if (product.Time > 0 && !_server._zoneConfig.vehicle.computerProduceInParallel && productionLine.Count > 0)
            {   //We can't do this
                player.sendMessage(-1, "Unable to produce - object is busy.");
                return(false);
            }

            int ammoUsed = 0;

            if (product.PlayerItemNeededId != 0)
            {
                int playerItemAmount = player.getInventoryAmount(product.PlayerItemNeededId);

                if (playerItemAmount == 0 || (product.PlayerItemNeededQuantity != -1 && product.PlayerItemNeededQuantity > playerItemAmount))
                {
                    player.sendMessage(-1, "You do not have the resources to produce this item.");
                    return(false);
                }
                ammoUsed = (product.PlayerItemNeededQuantity == -1) ? playerItemAmount : product.PlayerItemNeededQuantity;
            }

            //Is this for our team?
            if (product.TeamItemNeededId != 0)
            {
                if (!Logic_Assets.BuildingCheck(player, product.TeamBuildingLogic))
                {
                    player.sendMessage(-1, "Your team does not have the required buildings to produce this item.");
                    Log.write(TLog.Warning, "Player {0} attempted to use vehicle ({1}) produce without the necessary buildings.", player._alias, computer._type.Name);
                    return(false);
                }
                int teamItemAmount = player._team.getInventoryAmount(product.TeamItemNeededId);

                //Queue'ing isnt enabled
                if (product.TeamQueueRequest < 1)
                {
                    if (teamItemAmount == 0 || (product.TeamItemNeededId != -1 && product.TeamItemNeededQuantity > teamItemAmount))
                    {
                        player.sendMessage(-1, "Your team does not have the resources to produce this item.");
                        return(false);
                    }
                }
                else if (product.TeamQueueRequest > 0)
                {
                    if (teamItemAmount == 0)
                    {
                        player.sendMessage(-1, "Your team doesn't have the required resources to produce this item.");
                        return(false);
                    }

                    if (product.TeamItemNeededId != -1 && product.TeamItemNeededQuantity > teamItemAmount)
                    {
                        player.sendMessage(-1, "Your team doesn't have enough resources, once your team does, the item will be produced automatically.");
                        //Lets remove the items
                        if (product.TeamItemNeededQuantity == -1)
                        {
                            player._team.removeAllItemFromTeamInventory(product.TeamItemNeededId);
                        }
                        else
                        {
                            if (!player._team.inventoryModify(product.TeamItemNeededId, -product.TeamItemNeededQuantity))
                            {
                                //Shouldn't get here
                                Log.write(TLog.Error, "Unable to take product item payment from player's team after verifying existence.");
                                return(false);
                            }
                        }

                        //Check production line first before creating a new one
                        bool found = false;
                        if (productionLine.Count > 0)
                        {
                            foreach (ProduceRequest check in productionLine.ToList())
                            {
                                if (check.team == player._team)
                                {
                                    found = true;
                                }
                            }
                        }

                        if (!found)
                        {
                            //Lets queue it up
                            lock (productionLine)
                            {
                                ProduceRequest que = new ProduceRequest();

                                que.computer = computer;
                                que.client   = player;
                                que.product  = product;

                                que.tickCompletion = Environment.TickCount + (product.Time * 10);
                                que.teamAmmoUsed   = teamItemAmount;
                                que.ammoUsed       = ammoUsed;
                                que.team           = player._team;

                                productionLine.Add(que);
                            }

                            //Lets take any items needed before returning
                            if (product.PlayerItemNeededId != 0)
                            {
                                if (product.PlayerItemNeededQuantity == -1)
                                {
                                    player.removeAllItemFromInventory(false, product.PlayerItemNeededId);
                                }
                                else
                                {
                                    if (!player.inventoryModify(false, product.PlayerItemNeededId, -product.PlayerItemNeededQuantity))
                                    {   //We shouldn't get here
                                        Log.write(TLog.Error, "Unable to take produce item payment from player after verifying existence.");
                                        return(false);
                                    }
                                }
                            }
                        }

                        return(true);
                    }
                }
            }

            if (product.PlayerItemNeededId != 0)
            {
                if (product.PlayerItemNeededQuantity == -1)
                {
                    player.removeAllItemFromInventory(false, product.PlayerItemNeededId);
                }
                else
                {
                    if (!player.inventoryModify(false, product.PlayerItemNeededId, -product.PlayerItemNeededQuantity))
                    {   //We shouldn't get here
                        Log.write(TLog.Error, "Unable to take produce item payment from player after verifying existence.");
                        return(false);
                    }
                }
            }

            if (product.TeamItemNeededId != 0)
            {
                if (product.TeamItemNeededQuantity == -1)
                {
                    player._team.removeAllItemFromTeamInventory(product.TeamItemNeededId);
                }
                else
                {
                    if (!player._team.inventoryModify(product.TeamItemNeededId, -product.TeamItemNeededQuantity))
                    {
                        //Shouldn't get here
                        Log.write(TLog.Error, "Unable to take product item payment from player's team after verifying existence.");
                        return(false);
                    }
                }
            }

            //Take our payment!
            player.Cash -= product.Cost;

            //Sync up!
            player.syncInventory();

            //Do we need to queue up this request?
            if (product.Time > 0)
            {
                lock (productionLine)
                {       //Queue up the production request
                    ProduceRequest req = new ProduceRequest();

                    req.computer = computer;
                    req.client   = player;
                    req.product  = product;

                    req.tickCompletion = Environment.TickCount + (product.Time * 10);
                    req.ammoUsed       = ammoUsed;

                    productionLine.Add(req);
                }

                return(true);
            }
            else
            {   //Execute it immediately
                return(produceItem(player, computer, product, ammoUsed));
            }
        }