public override bool HandleCommand(ulong userId, string[] words) { MyObjectBuilder_Faction currentfaction; try { currentfaction = Faction.getFaction(Faction.getFactionID(userId)); } catch (NullReferenceException) { ChatUtil.SendPrivateChat(userId, "Faction has 0 FactionPoints"); return false; } int currentFP = FactionPoints.getFP(Convert.ToUInt64( Faction.getFactionID(userId))); if (currentFP != -1) { ChatUtil.SendPrivateChat(userId, "Faction Currently has " + currentFP + " FactionPoints."); } else { ChatUtil.SendPrivateChat(userId, "Faction does not exist."); } return true; }
public static bool transferFP(ulong userID, string factiontag, int amount) { if (amount < 0) { ChatUtil.SendPrivateChat(userID, "Please enter a positive value"); return(false); } if (Faction.getFactionIDfromTag(factiontag) != 0) { if (FactionPoints.RemoveFP((ulong)Faction.getFactionID(userID), amount) == true) { FactionPoints.AddFP(Faction.getFactionIDfromTag(factiontag), amount); return(true); } else { return(false); } } else { ChatUtil.SendPrivateChat(userID, "Factionx tag does not exist"); return(false); } }
public override void Handle() { // * Faction Points System: Every 60 minutes, Give each faction (owned asteroids) number of credits. Save faction balances to file. // ---------------------- try { MyObjectBuilder_FactionCollection factionlist = MyAPIGateway.Session.GetWorld().Checkpoint.Factions; int num_factions = factionlist.Factions.Count; //get number of factions ulong[,] fcleaderboard = new ulong[num_factions, 2]; foreach (MyObjectBuilder_Faction faction in factionlist.Factions) { int faction_score = 0; List <MyObjectBuilder_FactionMember> currentfaction = faction.Members; foreach (MyObjectBuilder_FactionMember currentmember in currentfaction) { var leaders = GMConquest.Instance.Leaderboard.GroupBy(x => x.Value).Select(group => new { group.Key, Total = group.Count() }).OrderByDescending(x => x.Total); foreach (var p in leaders) { if (p.Key == currentmember.PlayerId) { faction_score += p.Total; } } } // Add faction_score to factions current credits. FactionPoints.AddFP(faction.FactionId, faction_score); } } catch (InvalidOperationException) { // Log Invalid Operation Log.Info("Caught Invalid Operation in FactionPoints Process."); } // ---------------------- base.Handle(); }
public static bool buyItem(string itemname, long buyamount, ulong userID) { ShopItems = getshoppinglist(ShopItems); DynShopPrices.DynPrices(ShopItems, Faction.getFactionID(userID)); //ChatUtil.SendPrivateChat(userID, "Buying Item."); long amount = -1; string itemnamelowerend = itemname.ToLower().Substring(1); string itemnamecapital = itemname.ToUpper().Substring(0, 1); itemname = itemnamecapital + itemnamelowerend; if (buyamount < 0) { ChatUtil.SendPrivateChat(userID, "Please enter a positive value."); return(false); } foreach (ShopItem item in ShopItems) { if (item.ItemName == itemname) { amount = item.ItemPrice * buyamount; } } if (amount == -1) { ChatUtil.SendPrivateChat(userID, "Item does not exist."); return(false); } long facID = Faction.getFactionID(userID); int intAmount = Convert.ToInt32(amount); if (ChatUtil.CheckPlayerIsInWorld(userID)) { if (!FactionPoints.RemoveFP(Convert.ToUInt64(facID), intAmount)) { ChatUtil.SendPrivateChat(userID, "You do not have sufficient points to complete your purchase."); return(false); } } else { return(false); } Boolean component = false; switch (itemname) { case ("UpgradedConstruction"): case ("AdvancedConstruction"): case ("QuantumConstruction"): { component = true; break; } default: break; } if (component) { ChatUtil.AddComp(userID, itemname, Convert.ToInt32(buyamount)); return(true); } else { ChatUtil.AddIngot(userID, itemname, Convert.ToInt32(buyamount)); return(true); } }