public void AddFund(IcPlayer player, float fundAmount) { if (player == null) { throw new ArgumentNullException(nameof(player)); } else if (fundAmount <= 0.0f) { throw new ArgumentOutOfRangeException($"Argument '{nameof(fundAmount)}' must be > 0"); } string playerName = player.PlayerName; if (funds.ContainsKey(playerName)) { funds[playerName] += fundAmount; } else { funds.Add(playerName, fundAmount); } player.Money -= fundAmount; player.SetObjectDirtyBit(DirtyBit.BitOccasional, true); }
public override void PlayerJoinEvent(IcPlayer player) { if (player.DAPlayer.FindObserver(nameof(RenSharpExamplePlayerObserver)) == null) { player.DAPlayer.AddObserver(new RenSharpExamplePlayerObserver()); } }
public float Refund(IcPlayer player) { if (player == null) { throw new ArgumentNullException(nameof(player)); } string playerName = player.PlayerName; if (funds.TryGetValue(playerName, out float fundAmount)) { funds.Remove(playerName); player.Money += fundAmount; player.SetObjectDirtyBit(DirtyBit.BitOccasional, true); DA.PagePlayer(player, $"You have been refunded {(int)fundAmount} credit(s) for the {DATranslationManager.Translate(BuildingObj)}."); return(fundAmount); } else { return(0.0f); } }
private bool ReFundChatCommand(IcPlayer player, string command, IDATokenClass text, TextMessageEnum chatType, object data) { // Acronym for a building is specified if (text.Size > 0) { string acronym = text[1]; MappedBuildingDefinition mappedDefinition = FindMappedDefinition(acronym); ICollection <IDefinitionClass> validatedDefinitions; if (mappedDefinition == null || (validatedDefinitions = mappedDefinition.ValidatedDefinitions) == null) { DA.PagePlayer(player, $"No building found for acronym '{acronym}'."); return(false); } IScriptableGameObj destroyedBuilding = FindDestroyedBuilding(validatedDefinitions, player.PlayerType); if (destroyedBuilding == null) { DA.PagePlayer(player, $"No destroyed building found for acronym '{acronym}'."); return(false); } if (!buildingFunds.TryGetValue(destroyedBuilding.ID, out BuildingFund fund) || fund.Refund(player) <= 0.0f) { DA.PagePlayer(player, $"You haven't funded the {DATranslationManager.Translate(destroyedBuilding)}."); return(false); } DA.TeamColorMessageWithTeamColor(player.PlayerType, $"{DA.MessagePrefix}{(int)(fund.TotalFunds + 0.5f)} out of {(int)(mappedDefinition.CalculateTotalRestoreCost(Engine.GetTeamPlayerCount(player.PlayerType)) + 0.5f)} credit(s) gathered to restore the {DATranslationManager.Translate(destroyedBuilding)}."); return(true); } else // Assume they want all their money back { int playerCount = Engine.GetTeamPlayerCount(player.PlayerType); float totalRefundAmount = 0.0f; foreach (BuildingFund fund in buildingFunds.Values) { float currentRefundAmount = fund.Refund(player); if (currentRefundAmount > 0.0f) { totalRefundAmount += currentRefundAmount; DA.TeamColorMessageWithTeamColor(player.PlayerType, $"{DA.MessagePrefix}{(int)(fund.TotalFunds + 0.5f)} out of {(int)(fund.MappedDefinition.CalculateTotalRestoreCost(playerCount) + 0.5f)} credit(s) gathered to restore the {DATranslationManager.Translate(fund.BuildingObj)}."); } } if (totalRefundAmount <= 0.0f) { DA.PagePlayer(player, "You haven't funded anything."); return(false); } return(true); } }
public override bool VehicleEntryRequest(IScriptableGameObj obj, IcPlayer player, ref int seat) { if (player.PlayerType != DAVehicleManager.GetTeam(Owner)) { return(false); //Prevent the enemy from stealing this vehicle. } return(true); }
private bool TotalFundChatCommand(IcPlayer player, string command, IDATokenClass text, TextMessageEnum chatType, object data) { if (!BRFEnabled) { DA.PagePlayer(player, "Building funding is not enabled for this map."); return(false); } string acronym = text[1]; MappedBuildingDefinition mappedDefinition = FindMappedDefinition(acronym); ICollection <IDefinitionClass> validatedDefinitions; if (mappedDefinition == null || (validatedDefinitions = mappedDefinition.ValidatedDefinitions) == null) { DA.PagePlayer(player, $"No building found for acronym '{acronym}'."); return(false); } IScriptableGameObj destroyedBuilding = FindDestroyedBuilding(validatedDefinitions, player.PlayerType); if (destroyedBuilding == null) { DA.PagePlayer(player, $"No destroyed building found for acronym '{acronym}'."); return(false); } if (mappedDefinition.RestoreCountExceeded) { DA.PagePlayer(player, $"The maximum amount of restores per map for the {DATranslationManager.Translate(destroyedBuilding)} is exceeded."); return(false); } if (!buildingFunds.TryGetValue(destroyedBuilding.ID, out BuildingFund fund)) { fund = new BuildingFund(mappedDefinition, destroyedBuilding.ID); buildingFunds.Add(destroyedBuilding.ID, fund); } float totalRestoreCost = mappedDefinition.CalculateTotalRestoreCost(Engine.GetTeamPlayerCount(player.PlayerType)); fund.NotifyPlayerContribution(player); DA.TeamColorMessageWithTeamColor(player.PlayerType, $"{DA.MessagePrefix}{(int)(fund.TotalFunds + 0.5f)} out of {(int)(totalRestoreCost + 0.5f)} credit(s) gathered to restore the {DATranslationManager.Translate(destroyedBuilding)}."); return(true); }
public void RefundAll() { foreach (var fundsPair in funds) { float playerFunds = fundsPair.Value; if (playerFunds > 0.0f) { IcPlayer player = Engine.FindPlayer(fundsPair.Key); if (player != null) { DA.PagePlayer(player, $"You have been refunded {(int)playerFunds} credit(s) for the {DATranslationManager.Translate(BuildingObj)}."); } } } funds.Clear(); }
public override void PlayerJoinEvent(IcPlayer player) { PlayerClass Player = PlayersDatabase.GetPlayer(player.PlayerName); if (Player != null) { if (!DisableList.Contains(Player.Sound.ToLower())) { if (Player.Delay < MinDelay && Player.Delay > MaxDelay) { DA.PrivateColorMessage(player, Color.Cyan, $"[Join Sounds] Server settings are changed and incompatible setting detected. Your delay has been reset to minimum. Please update your delay with \"{CmdTriggers.Split('|')[0]} delay\"."); Player.Delay = MinDelay; PlayersDatabase.Update(player.PlayerName, Player); } StartTimer(player.PlayerId, FloatToTime(Player.Delay), false, new KeyValuePair <IcPlayer, PlayerClass>(player, Player)); } else { DA.PrivateColorMessage(player, Color.Cyan, $"[Join Sounds] Server settings are changed and incompatible setting detected. Your join sound is no longer available. Please update your sound with \"{CmdTriggers.Split('|')[0]} set\". Your join sound is removed."); PlayersDatabase.Remove(player.PlayerName); } } }
public override void RemoveWeaponEvent(IcPlayer player, IWeaponClass weapon) { }
public override bool AddWeaponRequestEvent(IcPlayer player, IWeaponDefinitionClass weapon) { return(true); }
public override void PowerUpGrantEvent(IcPlayer player, IPowerUpGameObjDef powerUp, IPowerUpGameObj powerUpObj) { }
public override void CharacterPurchaseEvent(IcPlayer player, float cost, ISoldierGameObjDef item) { }
public void NotifyPlayerContribution(IcPlayer player) { funds.TryGetValue(player.PlayerName, out float playerFunds); DA.PagePlayer(player, $"Your contribution towards restoring the {DATranslationManager.Translate(BuildingObj)} is {(int)playerFunds} credit(s)."); }
public override bool TeamChangeRequestEvent(IcPlayer player) { return(true); }
public override bool RequestVehicleEvent(IVehicleFactoryGameObj factory, IVehicleGameObjDef vehicle, IcPlayer player, float delay) { return(true); }
public override bool RefillEvent(IcPlayer player) { return(true); }
public override bool SuicideEvent(IcPlayer player) { return(true); }
public override void CustomPurchaseEvent(IcPlayer player, float cost, uint id) { }
public override void PowerUpPurchaseEvent(IcPlayer player, float cost, IPowerUpGameObjDef item) { }
public override void VehiclePurchaseEvent(IcPlayer player, float cost, IVehicleGameObjDef item) { }
public override void ClearWeaponsEvent(IcPlayer player) { }
public override int PowerUpPurchaseRequestEvent(IBaseControllerClass baseController, IcPlayer player, ref float cost, IPowerUpGameObjDef item) { return(-1); }
public override void ChangeCharacterEvent(IcPlayer player, ISoldierGameObjDef soldier) { }
public override bool VehicleEntryRequestEvent(IVehicleGameObj vehicle, IcPlayer player, ref int seat) { return(true); }
public override void PokeEvent(IcPlayer player, IPhysicalGameObj obj) { }
public override void VehicleExitEvent(IVehicleGameObj vehicle, IcPlayer player, int seat) { }
public override int CharacterPurchaseRequestEvent(IBaseControllerClass baseController, IcPlayer player, ref float cost, ISoldierGameObjDef item) { return(-1); }
public override bool PowerUpGrantRequestEvent(IcPlayer player, IPowerUpGameObjDef powerUp, IPowerUpGameObj powerUpObj) { return(true); }
public override void TeamChangeEvent(IcPlayer player) { }
public override int CustomPurchaseRequestEvent(IBaseControllerClass baseController, IcPlayer player, ref float cost, uint id) { return(-1); }