protected void OnPlayerConnecting([FromSource] Player player, string playerName, dynamic setKickReason, dynamic deferrals) { deferrals.defer(); deferrals.update("Retrieving connection lottery information..."); /* * if (ServerInfo.Clients < ServerInfo.MaxClients) * { * deferrals.done(); * } * else*/ { ConnectingPlayer connectingPlayer = new ConnectingPlayer(player, setKickReason, deferrals, DEFAULT_TIMEOUT_MS); int ticket = lottery.Add(connectingPlayer); // Remove connecting player from lottery on loading timeout. connectingPlayer.OnTimeout += (() => { lottery.Remove(connectingPlayer); }); } }
public int itemsAmount = 1; // Amount of rewards given public void PickRewards(bool onlyUnique, Action <List <LootBoxReward> > callback) { // Contruction de la lottery Lottery <LootBoxReward> lot = new Lottery <LootBoxReward>(); foreach (var reward in possibleItems) { // Conditions to adding an item in rewards here : // example : this items in the ref is not yet available by the player so it needs to not appear in lootbox reward // If player already has item and we want only unique reward if (reward.Key.PlayerAlreadyHasIt() && onlyUnique) { continue; } lot.Add(reward.Key, reward.Value); } List <LootBoxReward> pickedItems = new List <LootBoxReward>(); //On pick for (int i = 0; i < itemsAmount; i++) { if (lot.Count <= 0) { break; // No rewards } int pickedIndex = -1; pickedItems.Add(lot.Pick(out pickedIndex)); lot.RemoveAt(pickedIndex); } callback(pickedItems); }
public VoronoiMap(TileType[] tileTypes) { for (byte i = 0; i < tileTypes.Length; i++) { lottery.Add(new Number() { Index = i }, tileTypes[i].Weight); } }
private EventType PickEventType() { Lottery <EventType> eventTypeLottery = new Lottery <EventType>(eventTypes.Count); for (int i = 0; i < eventTypes.Count; i++) { float rate = eventTypes[i].distribution.Evaluate(depthRatio) * (eventTypes[i].maxRate - eventTypes[i].minRate) + eventTypes[i].minRate; eventTypeLottery.Add(eventTypes[i], rate); } return(eventTypeLottery.Pick()); }
//private void GenerateBorder() //{ // mapWidth += BorderSize * 2; // mapHeight += BorderSize * 2; // byte[,] mapWithBorder = new byte[mapWidth, mapHeight]; // for(int x = BorderSize; x < mapWidth-BorderSize; x++) // { // for(int y = BorderSize; y < mapHeight-BorderSize; y++) // { // mapWithBorder[x, y] = map[x - BorderSize, y - BorderSize]; // } // } // map = mapWithBorder; //} private void GenerateItemSpawnLotteries() { itemSpawnLottery = new Lottery <GameObject>(); foreach (ItemSpawn item in ItemSpawns) { itemSpawnLottery.Add(item.ItemPrefab, item.Weight); } foreach (TileType type in TileTypes) { foreach (ItemSpawn item in type.UniqueItemForTileType) { type.ItemSpawnLottery.Add(item.ItemPrefab, item.Weight); } } }
public async Task Fish(CommandContext ctx) { //Ablauf was alles passieren muss: //-zukünftig evtl Minispiel //-Player muss eine Standardzeit - Bonuszeit von Ausrüstung warten //✔️Fish wird generiert & Bild von dem Fish wird in den Channel gepostet //✔️Fish wird dem Player im Inventar hinzugefügt //✔️Wenn man mit Ködern Angelt werden diese auch abgezogen //Was muss alles gegeben sein damit man fischen kann: //-Es muss aktiv eine fishing rod ausgerüstet sein //✔️Man muss an einer Insel stehen //-Man darf nicht schon überladen sein //->Eventuell berechnung von Max. Gewicht was man finden kann + aktuelles Gewicht < Max gewicht??? // Player player = checkPlayer(ctx.Member.Id); if (player.id == -1) { await ctx.Channel.SendMessageAsync("Please register first.").ConfigureAwait(false); return; } else if ((bool)player.locked) { await ctx.Channel.SendMessageAsync("You can't do that at this moment").ConfigureAwait(false); return; } lockPlayer(player.id); Random rnd = new Random(); var fishingRod = "Obsidian Fishing Pole"; int? amount = null; //Ködern abziehen if (player.equippedBaitId > 0) { amount = insertPlayerInventory(player.id, (int)player.equippedBaitId, 2, -1); if (amount < 0 || !amount.HasValue) { await ctx.Channel.SendMessageAsync("You don't have enough bait for this action.").ConfigureAwait(false); return; } } var msg = await ctx.Channel.SendMessageAsync($"You cast your {fishingRod}.").ConfigureAwait(false); List <Fish> fishPool = getFishPool((int)player.currentIslandId, player.equippedBaitId); var lottery = new Lottery <string>(); foreach (var fishType in fishPool) { lottery.Add(fishType.name, (double)fishType.percentage); } string caughtFishName = lottery.Draw(true).Key; int caughtFishId = fishPool.Where(x => x.name == caughtFishName).Select(x => x.id).First(); Item caughtFish = selectItem(caughtFishId); await Task.Delay(2000); var caughtFishAmount = insertPlayerInventory(player.id, caughtFish.id, 1, 1); Tuple <int, int> level = addPlayerXp(player.id, (int)caughtFish.xp); var catchMsgBuilder = new DiscordEmbedBuilder() { Title = "Success!", Description = $"You caught a {caughtFishName}!\nYou gained {caughtFish.xp} experience.\n{(level.Item1 == 1 ? $"You leveled up! You are now level {level.Item2}\n" : string.Empty)}" + $"You alreday got caught {caughtFishAmount} {caughtFish.name}{(player.equippedBaitId == 0 ? string.Empty : $"\nYou got {amount} bait left")}", ImageUrl = caughtFish.imageURL }; await ctx.Channel.SendMessageAsync(catchMsgBuilder).ConfigureAwait(false); unlockPlayer(player.id); return; }