本文整理汇总了C#中LuaTable.Add方法的典型用法代码示例。如果您正苦于以下问题:C# LuaTable.Add方法的具体用法?C# LuaTable.Add怎么用?C# LuaTable.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LuaTable
的用法示例。
在下文中一共展示了LuaTable.Add方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetDedicatedServerStartSetup
/// <summary>
/// Sets up all the things that Springie needs to know for the battle: how to balance, who to get extra commanders,
/// what PlanetWars structures to create, etc.
/// </summary>
public static LobbyHostingContext GetDedicatedServerStartSetup(LobbyHostingContext context)
{
var ret = context;
try
{
var mode = context.Mode;
var commProfiles = new LuaTable();
var db = new ZkDataContext();
// calculate to whom to send extra comms
var accountIDsWithExtraComms = new List<int>();
if (mode == AutohostMode.Planetwars || mode == AutohostMode.GameFFA || mode == AutohostMode.Teams)
{
var groupedByTeam = context.Players.Where(x => !x.IsSpectator).GroupBy(x => x.AllyID).OrderByDescending(x => x.Count());
var biggest = groupedByTeam.FirstOrDefault();
if (biggest != null)
{
foreach (var other in groupedByTeam.Skip(1))
{
var cnt = biggest.Count() - other.Count();
if (cnt > 0)
{
foreach (var a in
other.Select(x => db.Accounts.First(y => y.AccountID == x.LobbyID))
.OrderByDescending(x => x.Elo*x.EloWeight)
.Take(cnt)) accountIDsWithExtraComms.Add(a.AccountID);
}
}
}
}
// write Planetwars details to modoptions (for widget)
Faction attacker = null;
Faction defender = null;
Planet planet = null;
if (mode == AutohostMode.Planetwars)
{
planet = db.Galaxies.First(x => x.IsDefault).Planets.First(x => x.Resource.InternalName == context.Map);
attacker =
context.Players.Where(x => x.AllyID == 0 && !x.IsSpectator)
.Select(x => db.Accounts.First(y => y.AccountID == x.LobbyID))
.Where(x => x.Faction != null)
.Select(x => x.Faction)
.First();
defender = planet.Faction;
if (attacker == defender) defender = null;
ret.ModOptions["attackingFaction"] = attacker.Shortcut;
if (defender != null) ret.ModOptions["defendingFaction"] = defender.Shortcut;
ret.ModOptions["planet"] = planet.Name;
}
// write player custom keys (level, elo, is muted, etc.)
foreach (var p in context.Players)
{
var user = db.Accounts.Where(x=>x.AccountID == p.LobbyID).Include(x=>x.RelalationsByOwner).FirstOrDefault();
if (user != null)
{
var userParams = new Dictionary<string, string>();
ret.UserParameters[p.Name] = userParams;
userParams["LobbyID"] = user.AccountID.ToString();
userParams["CountryCode"] = user.Country;
var userBanMuted = user.PunishmentsByAccountID.Any(x => !x.IsExpired && x.BanMute);
if (userBanMuted) userParams["muted"] = "1";
userParams["faction"] = user.Faction != null ? user.Faction.Shortcut : "";
userParams["clan"] = user.Clan != null ? user.Clan.Shortcut : "";
userParams["clanfull"] = user.Clan != null ? user.Clan.ClanName : "";
userParams["level"] = user.Level.ToString();
var elo = user.EffectiveMmElo;
userParams["elo"] = Math.Round(elo).ToString();
userParams["skill_order"] = ((context.IsMatchMakerGame ? user.CompetitiveRank : user.CasualRank) ?? int.MaxValue).ToString(); // send order of skills (For lists). Note this should be improved by sendng normalized list instead of ranks
userParams["avatar"] = user.Avatar;
userParams["admin"] = user.IsZeroKAdmin ? "1" : "0";
var userSpecChatBlocked = user.PunishmentsByAccountID.Any(x => !x.IsExpired && x.BanSpecChat);
userParams["can_spec_chat"] = userSpecChatBlocked ? "0" : "1";
userParams["ignored"] = string.Join(",", user.RelalationsByOwner.Where(x => x.Relation == Relation.Ignore).Select(x=>x.Target.Name));
userParams["friends"] = string.Join(",", user.RelalationsByOwner.Where(x => x.Relation == Relation.Friend).Select(x=>x.Target.Name));
if (!p.IsSpectator)
{
// set valid PW structure attackers
if (mode == AutohostMode.Planetwars)
{
var allied = user.Faction != null && defender != null && user.Faction != defender &&
defender.HasTreatyRight(user.Faction, x => x.EffectPreventIngamePwStructureDestruction == true, planet);
if (!allied && user.Faction != null && (user.Faction == attacker || user.Faction == defender))
//.........这里部分代码省略.........
示例2: MsgUnPackTable
public static bool MsgUnPackTable(out LuaTable luatable, ref MessagePackObject pObj)
{
LuaTable result = new LuaTable();
luatable = result;
var mPk = pObj.AsDictionary();
bool isString = false;
string key;
object value;
foreach (var item in mPk)
{
//parse for key
MessagePackObject mKey = item.Key;
if (mKey.IsRaw)
{
key = mKey.AsString();
isString = true;
}
else if (true == mKey.IsTypeOf<double>())
{
key = mKey.AsDouble().ToString();
}
else
{
LoggerHelper.Error("key type error");
return false;
}
//parse for value
MessagePackObject mValue = item.Value;
if (mValue.IsRaw)
{
value = mValue.AsString();
}
else if (mValue.IsDictionary)
{
LuaTable luatbl;
MsgUnPackTable(out luatbl, ref mValue);
value = luatbl;
}
else if (true == mValue.IsTypeOf<bool>())
{
value = mValue.AsBoolean();
}
else if (true == mValue.IsTypeOf<double>())
{
value = mValue.AsDouble();
}
else
{
LoggerHelper.Error("value type error");
return false;
}
result.Add(key, isString, value);
isString = false;
}
return true;
}
示例3: GetSpringBattleStartSetup
static bool listOnlyThatLevelsModules = false; // may cause bugs
public static SpringBattleStartSetup GetSpringBattleStartSetup(BattleContext context) {
try {
AutohostMode mode = context.GetMode();
var ret = new SpringBattleStartSetup();
if (mode == AutohostMode.Planetwars)
{
ret.BalanceTeamsResult = Balancer.BalanceTeams(context, true,null, null);
context.Players = ret.BalanceTeamsResult.Players;
}
var commanderTypes = new LuaTable();
var db = new ZkDataContext();
var accountIDsWithExtraComms = new List<int>();
// calculate to whom to send extra comms
if (mode == AutohostMode.Planetwars || mode == AutohostMode.Generic || mode == AutohostMode.GameFFA ||
mode == AutohostMode.Teams) {
IOrderedEnumerable<IGrouping<int, PlayerTeam>> groupedByTeam =
context.Players.Where(x => !x.IsSpectator).GroupBy(x => x.AllyID).OrderByDescending(x => x.Count());
IGrouping<int, PlayerTeam> biggest = groupedByTeam.FirstOrDefault();
if (biggest != null) {
foreach (var other in groupedByTeam.Skip(1)) {
int cnt = biggest.Count() - other.Count();
if (cnt > 0) {
foreach (Account a in
other.Select(x => db.Accounts.First(y => y.AccountID == x.LobbyID)).OrderByDescending(x => x.Elo*x.EloWeight).Take(
cnt)) accountIDsWithExtraComms.Add(a.AccountID);
}
}
}
}
bool is1v1 = context.Players.Where(x => !x.IsSpectator).ToList().Count == 2 && context.Bots.Count == 0;
Faction attacker = null;
Faction defender = null;
Planet planet = null;
if (mode == AutohostMode.Planetwars) {
planet = db.Galaxies.First(x => x.IsDefault).Planets.First(x => x.Resource.InternalName == context.Map);
attacker =
context.Players.Where(x => x.AllyID == 0 && !x.IsSpectator)
.Select(x => db.Accounts.First(y => y.AccountID == x.LobbyID))
.Where(x => x.Faction != null)
.Select(x => x.Faction)
.First();
defender = planet.Faction;
if (attacker == defender) defender = null;
ret.ModOptions.Add(new SpringBattleStartSetup.ScriptKeyValuePair { Key = "attackingFaction", Value = attacker.Shortcut });
if (defender != null) ret.ModOptions.Add(new SpringBattleStartSetup.ScriptKeyValuePair { Key = "defendingFaction", Value = defender.Shortcut });
ret.ModOptions.Add(new SpringBattleStartSetup.ScriptKeyValuePair { Key = "planet", Value = planet.Name });
}
foreach (PlayerTeam p in context.Players) {
Account user = db.Accounts.Find(p.LobbyID);
if (user != null) {
var userParams = new List<SpringBattleStartSetup.ScriptKeyValuePair>();
ret.UserParameters.Add(new SpringBattleStartSetup.UserCustomParameters { LobbyID = p.LobbyID, Parameters = userParams });
bool userBanMuted = user.PunishmentsByAccountID.Any(x => !x.IsExpired && x.BanMute);
if (userBanMuted) userParams.Add(new SpringBattleStartSetup.ScriptKeyValuePair { Key = "muted", Value = "1" });
userParams.Add(new SpringBattleStartSetup.ScriptKeyValuePair
{ Key = "faction", Value = user.Faction != null ? user.Faction.Shortcut : "" });
userParams.Add(new SpringBattleStartSetup.ScriptKeyValuePair
{ Key = "clan", Value = user.Clan != null ? user.Clan.Shortcut : "" });
userParams.Add(new SpringBattleStartSetup.ScriptKeyValuePair { Key = "level", Value = user.Level.ToString() });
double elo = mode == AutohostMode.Planetwars ? user.EffectivePwElo : (is1v1 ? user.Effective1v1Elo : user.EffectiveElo);
userParams.Add(new SpringBattleStartSetup.ScriptKeyValuePair { Key = "elo", Value = Math.Round(elo).ToString() }); // elo for ingame is just ordering for auto /take
userParams.Add(new SpringBattleStartSetup.ScriptKeyValuePair { Key = "avatar", Value = user.Avatar });
userParams.Add(new SpringBattleStartSetup.ScriptKeyValuePair { Key = "admin", Value = (user.IsZeroKAdmin ? "1" : "0") });
if (!p.IsSpectator) {
if (mode == AutohostMode.Planetwars)
{
bool allied = user.Faction != null && defender != null && user.Faction != defender &&
defender.HasTreatyRight(user.Faction, x => x.EffectPreventIngamePwStructureDestruction == true, planet);
if (!allied && user.Faction != null && (user.Faction == attacker || user.Faction == defender)) {
userParams.Add(new SpringBattleStartSetup.ScriptKeyValuePair { Key = "canAttackPwStructures", Value = "1" });
}
}
var pu = new LuaTable();
bool userUnlocksBanned = user.PunishmentsByAccountID.Any(x => !x.IsExpired && x.BanUnlocks);
bool userCommandersBanned = user.PunishmentsByAccountID.Any(x => !x.IsExpired && x.BanCommanders);
if (!userUnlocksBanned) {
if (mode != AutohostMode.Planetwars || user.Faction == null) foreach (Unlock unlock in user.AccountUnlocks.Select(x => x.Unlock)) pu.Add(unlock.Code);
else {
foreach (Unlock unlock in
user.AccountUnlocks.Select(x => x.Unlock).Union(user.Faction.GetFactionUnlocks().Select(x => x.Unlock)).Where(x => x.UnlockType == UnlockTypes.Unit)) pu.Add(unlock.Code);
//.........这里部分代码省略.........
示例4: PackLuaTable
/// <summary>
/// 转换字典类型的对象到LuaTable。
/// </summary>
/// <param name="target"></param>
/// <param name="result"></param>
/// <returns></returns>
public static bool PackLuaTable(IDictionary target, out LuaTable result)
{
Type[] types = target.GetType().GetGenericArguments();
result = new LuaTable();
try
{
foreach (DictionaryEntry item in target)
{
if (IsBaseType(types[1]))
{
object value;
if (types[1] == typeof(bool))//判断值是否布尔类型,是则做特殊转换
value = (bool)item.Value ? 1 : 0;
else
value = item.Value;
if (types[0] == typeof(int))//判断键是否为整型,是则标记键为整型,转lua table字符串时有用
result.Add(item.Key.ToString(), false, value);
else
result.Add(item.Key.ToString(), value);
}
else
{
LuaTable value;
var flag = PackLuaTable(item.Value, out value);
if (flag)
{
if (types[0] == typeof(int))
result.Add(item.Key.ToString(), false, value);
else
result.Add(item.Key.ToString(), value);
}
}
}
}
catch (Exception ex)
{
LoggerHelper.Error("PackLuaTable dictionary error: " + ex.Message);
}
return true;
}
示例5: DecodeLuaTable
private static bool DecodeLuaTable(byte[] inputString, ref int index, out object result)
{
var luaTable = new LuaTable();
result = luaTable;
if (!WaitChar(inputString, '{', ref index))
{
return false;
}
try
{
if (WaitChar(inputString, '}', ref index))//如果下一个字符为右大括号表示为空Lua table
return true;
while (index < inputString.Length)
{
string key;
bool isString;
object value;
DecodeKey(inputString, ref index, out key, out isString);//匹配键
WaitChar(inputString, '=', ref index);//匹配键值对分隔符
var flag = DecodeLuaValue(inputString, ref index, out value);//转换实体
if (flag)
{
luaTable.Add(key, isString, value);
}
if (!WaitChar(inputString, ',', ref index))
break;
}
WaitChar(inputString, '}', ref index);
return true;
}
catch (Exception e)
{
LoggerHelper.Error("Parse LuaTable error: " + inputString + e.ToString());
return false;
}
}
示例6: CreateMemberListTable
private LuaTable CreateMemberListTable(MoaiType type)
{
var memberListTable = new LuaTable();
memberListTable.Add(new LuaComment("Direct members"));
IEnumerable<MoaiTypeMember> directMembers = type.Members
.OrderBy(member => member.GetType().Name) // MoaiAttribute, then MoaiConstant, MoaiFlag, MoaiMethod
.ThenBy(member => member.Name);
foreach (var member in directMembers) {
memberListTable.Add(member.Name, CreateMemberTable((dynamic) member));
}
if (type.InheritedMembers.Any()) {
memberListTable.Add(new LuaComment("Inherited members", blankLineBefore: true));
var inheritedMembers = type.InheritedMembers
.OrderBy(member => member.GetType().Name)
.ThenBy(member => member.Name);
foreach (var member in inheritedMembers) {
memberListTable.Add(member.Name, CreateMemberTable((dynamic) member));
}
}
return memberListTable;
}
示例7: CreateTypeListTable
private LuaTable CreateTypeListTable(IEnumerable<MoaiType> types)
{
var typeListTable = new LuaTable();
foreach (MoaiType type in types.OrderBy(t => t.Name)) {
typeListTable.Add(new LuaComment(type.Signature, blankLineBefore: typeListTable.Any()));
typeListTable.Add(type.Name, CreateTypeTable(type));
}
return typeListTable;
}
示例8: SendClientMissionMessage
protected void SendClientMissionMessage()
{
// 真正向服务器发, to do
LuaTable result = new LuaTable();
LuaTable temp;
Mogo.RPC.Utils.PackLuaTable(localAvatarCollectedDrops, out temp);
result.Add(1, temp);
result.Add(2, localAvatarCollectedMoney);
result.Add(3, localAvatarCollectedExp);
MogoWorld.thePlayer.RpcCall("MissionExReq", (byte)MissionHandleCode.UPLOAD_COMBO_AND_BOTTLE, (ushort)localAvatarCombo, (ushort)localAvatarBottle, (ushort)(localServerAvatar.defaultReviveTimes - localServerAvatar.reviveTimes), Mogo.RPC.Utils.PackLuaTable(result));
}