/// <summary> /// Uses the event state to exact appropriate action /// </summary> static private void executeState(Player player, EventState state) { //Do we need to be warping? if (state.bWarping && !state.bWarpInPlace) { //Get our warpgroup IEnumerable <LioInfo.WarpField> wGroup = state.warpGroup; if (wGroup == null) { //Lets attempt to use the default warpgroup wGroup = player._server._assets.Lios.getWarpGroupByID(0); if (wGroup == null) { Log.write(TLog.Error, "Warp group '0' doesn't exist."); return; } } //Great! Apply the warp Logic_Lio.Warp(state.warpFlags, player, wGroup); } else if (state.bWarping && state.bWarpInPlace) { short energy = player._state.energy; if (state.warpFlags == Helpers.ResetFlags.ResetAll || state.warpFlags == Helpers.ResetFlags.ResetEnergy) { energy = -1; } //We want to warp in place player.warp(state.warpFlags, energy, player._state.positionX, player._state.positionY); } }
/// <summary> /// Parses event strings and executes the given actions /// </summary> static private bool executeAction(bool bEnforceState, Player player, string action, string param, EventState state) { //What sort of action? bool bChangedState = false; //Trim our strings.. action = action.Trim('"'); param = param.Trim('"'); switch (action) { //Gives the player the specified item case "addinv": { //Check for a quantity int colIdx = param.IndexOf(':'); if (colIdx == -1) { //Find the given item ItemInfo item = player._server._assets.getItemByName(param); if (item != null) { player.inventoryModify(false, item, 1); } } else { //Find the given item ItemInfo item = player._server._assets.getItemByName(param.Substring(0, colIdx)); if (item != null) { player.inventoryModify(false, item, Convert.ToInt32(param.Substring(colIdx + 1))); } } bChangedState = true; //player.syncState(); } break; //Sends the player to the specified lio warp group case "warp": { //Only in an arena if (player._arena == null) { break; } //Default to warpgroup 0 int warpGroup = 0; if (param != "") { warpGroup = Convert.ToInt32(param); } //Find our group IEnumerable <LioInfo.WarpField> wGroup = player._server._assets.Lios.getWarpGroupByID(warpGroup); if (wGroup == null) { Log.write(TLog.Error, "Warp group '{0}' doesn't exist.", param); break; } //We have our group, set it in the state state.bWarping = true; state.bWarpInPlace = false; state.warpGroup = wGroup; Logic_Lio.Warp(state.warpFlags, player, wGroup); } break; //Sets the player's experience to the amount defined case "setexp": player.Experience = Convert.ToInt32(param); bChangedState = true; player.syncState(); break; //Sets the player's cash to the amount defined case "setcash": player.Cash = Convert.ToInt32(param); bChangedState = true; player.syncState(); break; //Sets the player's bounty to the amount given case "setbounty": player.Bounty = Convert.ToInt32(param); bChangedState = true; player.syncState(); break; //Adds the amount given to the player's experience case "addexp": player.Experience += Convert.ToInt32(param); bChangedState = true; player.syncState(); break; //Adds the amount given to the player's cash case "addcash": player.Cash += Convert.ToInt32(param); bChangedState = true; player.syncState(); break; //Add the amount of bounty to the player case "addbounty": player.Bounty += Convert.ToInt32(param); bChangedState = true; player.syncState(); break; //Sets the player's energy to the amount defined case "setenergy": //TODO: Figure out how to implement this int energy; if (Int32.TryParse(param, out energy)) { //Log.write(TLog.Warning, " Setting {0} to {1} nrg", player._alias, energy); player.setEnergy((short)energy); bChangedState = true; player.syncState(); } break; //Wipes all player attributes case "wipeattr": if (param == "") { //Wipe all attributes List <Player.SkillItem> removes = player._skills.Values.Where(skl => skl.skill.SkillId < 0).ToList(); foreach (Player.SkillItem skl in removes) { player._skills.Remove(skl.skill.SkillId); } bChangedState = true; player.syncState(); } else { Log.write(TLog.Warning, "Use wipeskill=attribute to wipe specific attributes"); } break; //Wipes all player skills case "wipeskill": if (param != "") { //Param is the name of the skill to remove OR the id int i; Int32.TryParse(param, out i); KeyValuePair <int, Player.SkillItem> skill = player._skills.FirstOrDefault(sk => i == sk.Key || param == sk.Value.skill.Name.ToLower()); if (skill.Key != 0) { player._skills.Remove(skill.Key); bChangedState = true; player.syncState(); } } else { //No parameters, erase all skills List <Player.SkillItem> removes = player._skills.Values.Where(sk => sk.skill.SkillId > 0).ToList(); foreach (Player.SkillItem sk in removes) { player._skills.Remove(sk.skill.SkillId); } bChangedState = true; player.syncState(); } break; //Wipes the player's inventory case "wipeinv": if (param != "") { //Erase all of a specified item int id; if (!Int32.TryParse(param, out id)) { ItemInfo item = player._server._assets.getItemByName(param); if (item == null) { return(false); } id = item.id; } player.removeAllItemFromInventory(true, id); } else { //Erase whole inventory player._inventory.Clear(); player.syncInventory(); bChangedState = true; } break; //Wipes the player's score case "wipescore": //TODO: Wipe the score break; //Resets the player's default vehicle case "reset": { //Only in an arena if (player._arena == null) { break; } state.bWarping = true; state.warpFlags = Helpers.ResetFlags.ResetAll; //Lets check for what they want to reset if (param != "") { switch (Convert.ToInt32(param)) { case 0: state.warpFlags = Helpers.ResetFlags.ResetNone; break; case 1: state.warpFlags = Helpers.ResetFlags.ResetEnergy; break; case 2: state.warpFlags = Helpers.ResetFlags.ResetHealth; break; case 3: //Dont know yet state.warpFlags = Helpers.ResetFlags.ResetAll; break; case 4: state.warpFlags = Helpers.ResetFlags.ResetVelocity; break; case 5: //Dont know yet case 6: //Dont know yet case 7: state.warpFlags = Helpers.ResetFlags.ResetAll; break; } } } break; //Gives the player the specified skill case "addskill": { //Find the given skill SkillInfo skill = player._server._assets.getSkillByName(param); if (skill != null) { player.skillModify(false, skill, 1); } bChangedState = true; player.syncState(); } break; //Triggers the first vehicle event string case "vehicleevent": case "vehicleevent1": if (player._baseVehicle != null) { //Get the vehicle string RunEvent(player, player._baseVehicle._type.EventString1, null); } break; //Triggers the first vehicle event string case "vehicleevent2": if (player._baseVehicle != null) { //Get the vehicle string RunEvent(player, player._baseVehicle._type.EventString2, null); } break; //Triggers the first vehicle event string case "vehicleevent3": if (player._baseVehicle != null) { //Get the vehicle string RunEvent(player, player._baseVehicle._type.EventString3, null); } break; //Triggers the team event string case "teamevent": //Execute! if (param != "") { RunEvent(player, player._team._info.eventString, state); } break; //Run the event for the terrain case "terrainevent": if (!player.IsSpectator) { RunEvent(player, player._arena.getTerrain(player._state.positionX, player._state.positionY).eventString, null); } break; } if (player._bIngame && bEnforceState && bChangedState) { player.syncState(); } return(bChangedState); }