private async void OnCustomDelete(object sender, EventArgs e, object v) { Xamarin.Forms.Button button = (Xamarin.Forms.Button)sender; RollItem delRoll = new RollItem { RollID = Convert.ToInt32(button.CommandParameter.ToString()) }; await App.Database.DeleteItemAsync(delRoll); SavedRollsView test = (SavedRollsView)v; test.RefreshView(); }
private int _Add <T, D> (T itemTemplate, D data, Action <T, D> setContentFunc, int priority, bool isPermanent, int sequence = -1) where T : MonoBehaviour { if (itemTemplate == null) { return(-1); } bool push = false; itemTemplate.gameObject.SetActive(false); RollItem currentItem = new RollItem(); if (sequence < 0) { sequence = ++curSequence; } var available = FindAvailable(priority); if (laterWhenFull && !IsAvailable() && available < 0) { laterQueue.Enqueue(() => { _Add <T, D> (itemTemplate, data, setContentFunc, priority, isPermanent, sequence); }); } else if (itemList.Count < maxItemCount) { currentItem = CreateItem(itemTemplate, priority, sequence, -1, isPermanent); itemList.Add(currentItem); currentItem.transform.gameObject.SetActive(true); push = true; } else if (available >= 0) { push = true; currentItem = itemList [available]; if (currentItem.type != typeof(T)) { Type type = typeof(T); if (cachedItems.ContainsKey(type) && cachedItems [type].Count > 0) { var cache = cachedItems [type]; currentItem = cache [cache.Count - 1]; cache.RemoveAt(cache.Count - 1); } else { currentItem.transform = CreateTransform(itemTemplate); currentItem.type = typeof(T); } var cacheType = itemList [available].type; if (!cachedItems.ContainsKey(cacheType)) { cachedItems.Add(cacheType, new List <RollItem> ()); } cachedItems [cacheType].Add(itemList [available]); } currentItem.sequence = sequence; currentItem.priority = priority; currentItem.curIndex = -1; currentItem.isPermanent = isPermanent; currentItem.isFinished = false; currentItem.type = typeof(T); itemList [available].transform.gameObject.SetActive(false); itemList [available] = currentItem; currentItem.transform.gameObject.SetActive(true); } if (push) { PushupItems(); if (setContentFunc != null) { setContentFunc(currentItem.transform.GetComponent <T> (), data); } } return(sequence); }
bool GiveRoll(PlayerSession session, string rollname) { Roll roll; if (string.IsNullOrEmpty(rollname) || !storedData.Rolls.TryGetValue(rollname, out roll)) { ShowMsg(session, Msg("GiveRoll_NotExist").Replace("{rollname}", rollname)); return(false); } var playerinv = session.WorldPlayerEntity.GetComponent <PlayerInventory>(); var amanager = Singleton <AlertManager> .Instance; var itemmanager = Singleton <GlobalItemManager> .Instance; var playerEntity = session.WorldPlayerEntity; var rolledItem = new RollItem(); var rolledReplacement = new RollItem(); var rolledStat = new RollStat(); var rolledSpawn = new RollSpawn(); var ManagerInstance = GameManager.Instance; var sumItemChance = 0; var sumStatChance = 0; var sumSpawnChance = 0; var sumReplaceChance = 0; var totalChance = 0; var count = 0; foreach (var rollem in roll.items) { sumItemChance += rollem.chance; } foreach (var rollstat in roll.stats) { sumStatChance += rollstat.chance; } foreach (var rollspawn in roll.spawns) { sumSpawnChance += rollspawn.chance; } foreach (var rollreplace in roll.replacements) { sumReplaceChance += rollreplace.chance; } totalChance = sumItemChance + sumStatChance + sumSpawnChance + sumReplaceChance; if (totalChance == 0) { return(false); } var rnd = Core.Random.Range(1, totalChance); if (rnd <= sumItemChance) { for (int i = 0; i < roll.items.Count && rolledItem.itemid == 0; i++) { count += roll.items[i].chance; if (count >= rnd) { rolledItem = roll.items[i]; } } var item = itemmanager.GetItem(rolledItem.itemid); var iitem = new ItemInstance(item, rolledItem.amount); if (playerinv.Items[0] == null) { playerinv.Items[0] = iitem; amanager.ItemReceivedServer(iitem.Item, iitem.StackSize, session.Player); playerinv.Invalidate(false); } else { itemmanager.GiveItem(session.Player, itemmanager.GetItem(rolledItem.itemid), rolledItem.amount); } BroadcastMsg(Msg("GiveRoll_ItemGive") .Replace("{player}", session.Name) .Replace("{amount}", rolledItem.amount.ToString()) .Replace("{itemname}", item.GetNameKey().ToString().Split('/').Last())); } else if (rnd > sumItemChance && rnd <= sumStatChance + sumItemChance) { count = sumItemChance; for (int i = 0; i < roll.stats.Count && rolledStat.type == 0; i++) { count += roll.stats[i].chance; if (count >= rnd) { rolledStat = roll.stats[i]; } } EntityStats stats = session.WorldPlayerEntity.GetComponent <EntityStats>(); var currValue = stats.GetFluidEffect(rolledStat.type).GetValue(); var newValue = currValue + rolledStat.amount; stats.GetFluidEffect(rolledStat.type).SetValue(newValue); BroadcastMsg(Msg("GiveRoll_StatGive") .Replace("{player}", session.Name) .Replace("{amount}", rolledStat.amount.ToString()) .Replace("{stat}", rolledStat.type.ToString().ToLower())); } else if (rnd > sumItemChance + sumStatChance && rnd <= sumStatChance + sumItemChance + sumSpawnChance) { count = sumItemChance + sumStatChance; GameObject Obj = new GameObject(); for (int i = 0; i < roll.spawns.Count && rolledSpawn.spawnName == null; i++) { count += roll.spawns[i].chance; if (count >= rnd) { rolledSpawn = roll.spawns[i]; } } var iterations = 0; var numberSpawned = 0; for (numberSpawned = 0; numberSpawned < rolledSpawn.amount && iterations < rolledSpawn.amount * 100;) { Vector3 position = new Vector3(playerEntity.transform.position.x + Core.Random.Range(-10, 10), playerEntity.transform.position.y + Core.Random.Range(0, 10), playerEntity.transform.position.z + Core.Random.Range(-10, 10)); RaycastHit hitInfo; Physics.Raycast(position, Vector3.down, out hitInfo); { Quaternion rotation = Quaternion.Euler(0.0f, (float)UnityEngine.Random.Range(0f, 360f), 0.0f); rotation = Quaternion.FromToRotation(Vector3.down, hitInfo.normal) * rotation; Obj = Singleton <HNetworkManager> .Instance.NetInstantiate(rolledSpawn.spawnName, hitInfo.point, Quaternion.identity, GameManager.GetSceneTime()); Destroy(Obj); numberSpawned++; } iterations++; } BroadcastMsg(Msg("GiveRoll_SpawnGive") .Replace("{player}", session.Name) .Replace("{amount}", numberSpawned.ToString()) .Replace("{creature}", creatures[rolledSpawn.spawnName.ToLower()])); } else { var replacementFound = false; count = sumStatChance + sumItemChance + sumSpawnChance; for (int i = 0; i < roll.replacements.Count && rolledReplacement.itemid == 0; i++) { count += roll.replacements[i].chance; if (count >= rnd) { rolledReplacement = roll.replacements[i]; } } if (playerinv.Items.Length > 0) { var noOfIterations = 0; for (int i = Core.Random.Range(0, playerinv.Items.Length - 1); !replacementFound && noOfIterations < 1000; i = Core.Random.Range(0, playerinv.Items.Length - 1)) { if (playerinv.Items[i] != null) { var item = itemmanager.GetItem(rolledReplacement.itemid); var iitem = new ItemInstance(item, rolledReplacement.amount); var replaceedItem = playerinv.Items[i]; playerinv.Items[i] = iitem; amanager.ItemReceivedServer(iitem.Item, iitem.StackSize, session.Player); playerinv.Invalidate(false); replacementFound = true; BroadcastMsg(Msg("GiveRoll_ItemReplace") .Replace("{player}", session.Name) .Replace("{amount1}", replaceedItem.StackSize.ToString()) .Replace("{itemname1}", replaceedItem.Item.GetNameKey().ToString().Split('/').Last()) .Replace("{amount2}", playerinv.Items[i].StackSize.ToString()) .Replace("{itemname2}", playerinv.Items[i].Item.GetNameKey().ToString().Split('/').Last())); } noOfIterations++; } } } return(true); }
void cmdRoll(PlayerSession session, string command, string[] args) { if (args.Length == 0) { var reason = string.Empty; foreach (var pair in storedData.Rolls) { var cansee = CanSeeRoll(session, pair.Key, out reason); if (!cansee && string.IsNullOrEmpty(reason)) { continue; } ShowMsg(session, Msg("CmdRoll_CantSeeRoll") .Replace("{rollname}", pair.Value.name) .Replace("{desc}", pair.Value.description) .Replace("{reason}", reason)); } return; } if (args.Length == 1) { switch (args[0]) { case "help": ShowMsg(session, Msg("CmdRoll_Player1")); ShowMsg(session, Msg("CmdRoll_Player2")); ShowMsg(session, Msg("CmdRoll_Player3")); if (!HasAccess(session)) { return; } ShowMsg(session, Msg("CmdRoll_Admin1")); ShowMsg(session, Msg("CmdRoll_Admin2")); ShowMsg(session, Msg("CmdRoll_Admin3")); ShowMsg(session, Msg("CmdRoll_Admin4")); ShowMsg(session, Msg("CmdRoll_Admin5")); ShowMsg(session, Msg("CmdRoll_Admin6")); ShowMsg(session, Msg("CmdRoll_Admin7")); ShowMsg(session, Msg("CmdRoll_Admin8")); break; case "add": case "remove": case "edit": if (!HasAccess(session)) { ShowMsg(session, Msg("CmdRoll_NoAccess")); return; } ShowMsg(session, Msg("CmdRoll_Admin4")); break; case "give": if (!HasAccess(session)) { ShowMsg(session, Msg("CmdRoll_NoAccess")); return; } ShowMsg(session, Msg("CmdRoll_Admin6")); break; case "list": if (!HasAccess(session)) { ShowMsg(session, Msg("CmdRoll_NoAccess")); return; } foreach (var roll in storedData.Rolls.Values) { ShowMsg(session, Msg("CmdRoll_RollList").Replace("{rollname}", roll.name).Replace("{description}", roll.description)); } break; case "additem": break; case "addstat": break; case "addspawn": break; case "addreplace": break; case "resetrolls": if (!HasAccess(session)) { ShowMsg(session, Msg("CmdRoll_NoAccess")); return; } storedData.Rolls.Clear(); rollEditor.Clear(); ResetData(); SaveRolls(); ShowMsg(session, Msg("CmdRoll_ResetAll")); break; case "resetdata": if (!HasAccess(session)) { ShowMsg(session, Msg("CmdRoll_NoAccess")); return; } ResetData(); ShowMsg(session, Msg("CmdRoll_ResetPlayer")); break; default: TryGiveRoll(session, args[0].ToLower()); break; } if (args[0] != "additem" && args[0] != "addstat" && args[0] != "addspawn" && args[0] != "addreplace") { return; } } if (!HasAccess(session)) { ShowMsg(session, Msg("CmdRoll_NoAccess")); return; } string rollname; switch (args[0]) { case "add": rollname = args[1].ToLower(); if (storedData.Rolls.ContainsKey(rollname)) { ShowMsg(session, Msg("CmdRoll_NewRollExists")); return; } storedData.Rolls[rollname] = new Roll { name = args[1] }; rollEditor[session.SteamId.m_SteamID] = rollname; ShowMsg(session, Msg("CmdRoll_NewRoll").Replace("{rollname}", args[1])); SendListRollEdition(session); break; case "give": if (args.Length < 3) { ShowMsg(session, Msg("CmdRoll_Admin6")); return; } rollname = args[2].ToLower(); if (!storedData.Rolls.ContainsKey(rollname)) { ShowMsg(session, Msg("CmdRoll_NewRollNotExists")); return; } var findPlayers = FindPlayer(args[1]); if (findPlayers.Count == 0) { ShowMsg(session, Msg("CmdRoll_GiveNoPlayer")); return; } if (findPlayers.Count > 1) { ShowMsg(session, Msg("CmdRoll_GiveMultiple")); return; } GiveRoll(findPlayers[0], rollname); ShowMsg(session, Msg("CmdRoll_Given").Replace("{player}", findPlayers[0].Name).Replace("{rollname}", storedData.Rolls[rollname].name)); ShowMsg(findPlayers[0], Msg("CmdRoll_GivenReceive").Replace("{player}", session.Name).Replace("{rollname}", storedData.Rolls[rollname].name)); break; case "edit": rollname = args[1].ToLower(); if (!storedData.Rolls.ContainsKey(rollname)) { ShowMsg(session, Msg("CmdRoll_NewRollNotExists")); return; } rollEditor[session.SteamId.m_SteamID] = rollname; ShowMsg(session, Msg("CmdRoll_Edit").Replace("{rollname}", rollname)); SendListRollEdition(session); break; case "remove": rollname = args[1].ToLower(); if (!storedData.Rolls.Remove(rollname)) { ShowMsg(session, Msg("CmdRoll_NewRollNotExists")); return; } ShowMsg(session, Msg("CmdRoll_Remove").Replace("{rollname}", rollname)); if (rollEditor[session.SteamId.m_SteamID] == rollname) { rollEditor.Remove(session.SteamId.m_SteamID); } break; default: if (!rollEditor.TryGetValue(session.SteamId.m_SteamID, out rollname)) { ShowMsg(session, Msg("CmdRoll_NotInEdit")); return; } Roll roll; if (!storedData.Rolls.TryGetValue(rollname, out roll)) { ShowMsg(session, Msg("CmdRoll_Dirty")); return; } for (var i = 0; i < args.Length; i++) { object editvalue; var key = args[i].ToLower(); switch (key) { case "additem": RollItem item = new RollItem(); item.itemid = Math.Abs(int.Parse(args[++i])); item.amount = Math.Abs(int.Parse(args[++i])); item.chance = Math.Abs(int.Parse(args[++i])); roll.items.Add(item); ShowMsg(session, Msg("CmdRoll_AddItem")); continue; case "addstat": RollStat stat = new RollStat(); var statType = args[++i].ToLower(); var statAmount = args[++i].ToLower(); var statChance = args[++i].ToLower(); bool statFound = true; switch (statType) { case "radiation": stat.type = EEntityFluidEffectType.Radiation; break; case "dampness": stat.type = EEntityFluidEffectType.Dampness; break; case "nutrition": stat.type = EEntityFluidEffectType.Nutrition; break; case "toxin": stat.type = EEntityFluidEffectType.Toxin; break; case "health": stat.type = EEntityFluidEffectType.Health; break; case "inttemp": stat.type = EEntityFluidEffectType.InternalTemperature; break; case "exttemp": stat.type = EEntityFluidEffectType.ExternalTemperature; break; case "infamy": stat.type = EEntityFluidEffectType.Infamy; break; default: statFound = false; break; } if (statFound) { stat.amount = int.Parse(statAmount); stat.chance = Math.Abs(int.Parse(statChance)); roll.stats.Add(stat); ShowMsg(session, Msg("CmdRoll_AddStat")); } continue; case "addspawn": RollSpawn spawn = new RollSpawn(); var spawnType = args[++i].ToLower(); var spawnAmount = args[++i].ToLower(); var spawnChance = args[++i].ToLower(); bool spawnFound = true; switch (spawnType) { case "bor": spawn.spawnName = "AIBorServer"; break; case "yeti": spawn.spawnName = "AIYetiServer"; break; case "tokar": spawn.spawnName = "AITokarServer"; break; default: spawnFound = false; break; } if (spawnFound) { spawn.amount = Math.Abs(int.Parse(spawnAmount)); spawn.chance = Math.Abs(int.Parse(spawnChance)); roll.spawns.Add(spawn); ShowMsg(session, Msg("CmdRoll_AddSpawn")); } continue; case "addreplace": RollItem itemReplace = new RollItem(); itemReplace.itemid = Math.Abs(int.Parse(args[++i])); itemReplace.amount = Math.Abs(int.Parse(args[++i])); itemReplace.chance = Math.Abs(int.Parse(args[++i])); roll.replacements.Add(itemReplace); ShowMsg(session, Msg("CmdRoll_AddReplace")); continue; case "name": continue; case "description": editvalue = roll.description = args[++i]; break; case "max": editvalue = roll.max = int.Parse(args[++i]); break; case "cooldown": editvalue = roll.cooldown = double.Parse(args[++i]); break; case "authlevel": editvalue = roll.authlevel = int.Parse(args[++i]); break; case "hide": editvalue = roll.hide = bool.Parse(args[++i]); break; case "permission": editvalue = roll.permission = args[++i]; InitializePermissions(); break; default: ShowMsg(session, Msg("CmdRoll_InvalidArgs").Replace("{arg}", args[i])); continue; } } break; } SaveRolls(); }
public void CustomRoll(RollItem item, bool isCrit) { string regx = @"[\[A-Z\]]"; string error = "Improper format. e.g. 8[d6]+[d4]+1"; string outputRoll = ""; string critInput = ""; string input = item.RollDice; string[] rolled = RollSplit(input); foreach (string r in rolled) { if (r.Contains('d')) { try { string[] diceRolled = Regex.Split(r, regx); List <string> diceRoll = new List <string>(); foreach (string d in diceRolled) { if (d != "") { diceRoll.Add(d); } } int rollCount = 1; int dieToRoll = 0; string[] die = new string[2]; if (diceRoll.Count == 1) { if (isCrit) { rollCount = 2; if (critInput == "") { critInput += String.Format(rollCount + "[" + diceRoll[0] + "]"); } else { critInput += String.Format(rollCount + "[" + diceRoll[0] + "]"); } } die = diceRoll[0].Split(new char[] { 'd' }, StringSplitOptions.RemoveEmptyEntries); dieToRoll = Convert.ToInt32(die[0]); } else if (diceRoll.Count == 2) { die = diceRoll[1].Split(new char[] { 'd' }, StringSplitOptions.RemoveEmptyEntries); dieToRoll = Convert.ToInt32(die[0]); rollCount = Convert.ToInt32(diceRoll[0]); if (isCrit) { rollCount = rollCount * 2; if (critInput == "") { critInput += String.Format(rollCount + "[" + diceRoll[1] + "]"); } else { critInput += String.Format(rollCount + "[" + diceRoll[1] + "]"); } } //split at d //set roll count to first number //set die to second number } else { throw new Exception(); } string[] diceResult = new string[rollCount]; string rollValue = ""; for (int i = 0; i < rollCount; i++) { diceResult[i] = RollDie(dieToRoll).ToString(); } foreach (string result in diceResult) { if (rollValue == "") { rollValue += result; } else { rollValue += "+" + result; } } outputRoll += rollValue; } catch { outputRoll = error; break; } } else { if (isCrit) { critInput += r; } outputRoll += r; } } if (isCrit) { RollOutput(critInput, outputRoll, false); } else { RollOutput(input, outputRoll, item.CanSave); } }