public RoomModel(string roomName, DomainModel model) { FunctionCalls = new FunctionCallsCollection(); //functionCalls; FileName = RoomModel.ConvertRoomNameToFullPath(roomName); RawFileName = roomName; //try loading pre-exiting file first. If you can't, //then create one from the default text file asset string roomPath = model.DomainRootDir + System.IO.Path.DirectorySeparatorChar.ToString() + model.IncludeFile.StripDeadSoulsPath(DeadSouls.Globals.DomainDirectories.Room); string fullFilePath = roomPath + System.IO.Path.DirectorySeparatorChar.ToString() + RawFileName; if (System.IO.File.Exists(fullFilePath)) { Code.LoadLPC(fullFilePath); } else { //failed to load throw new DomainModelException("Could not find file for room: " + roomName); } this.EditorState.Reset(); PullDataFromCode(); }
private bool Serialize(string filePath, FunctionCallsCollection functions, FunctionCallsCollection inherits) { PushFunctionDataToCode(functions); //update parse map PushInheritDataToCode(inherits); StringBuilder str = new StringBuilder(); foreach (Parser.Token token in this.Code.Tokens) { str.Append(token.GetCode(Globals.WorkspaceSave.LineEndingMap[Globals.WorkspaceSave.LineEndings])); } //make sure this is what we want if (System.IO.File.Exists(filePath)) { if (MessageBox.Show("A file with this name already exists in this location. Do you want to overwrite it?", "File Already Exists", MessageBoxButtons.YesNo) == DialogResult.No) { return(false); } } using (System.IO.StreamWriter stream = new System.IO.StreamWriter(filePath, false, Globals.WorkspaceSave.LPCEncoding)) { stream.Write(str); stream.Flush(); } return(true); }
/// <summary> /// Collects all controls that represent a function call, and stores their processed /// output in a list of FunctionCall objects. /// </summary> /// <param name="controls"></param> /// <returns></returns> public FunctionCallsCollection CompileFunctioCallsList(List <IFunctionControl> controls) { FunctionCallsCollection collection = new FunctionCallsCollection(); foreach (IFunctionControl control in controls) { try { //only collect if enabled and it represents an actual function call if (control.Enabled && control.ParameterType != FuncParamType.Inherit) { string parameters = control.PullEntry(); collection.DefineCall(control.FunctionName, parameters); if (parameters.Length > 0 && parameters != null && parameters != "({})" && parameters != "([])" && parameters != "\"\"") { collection.AddHeaderFile(control.RequiredHeader); } } } catch (FunctionControlException e) { MessageBox.Show(e.Message, Globals.ErrorStrings.FunctionControlErrorTitle); } catch (ParserException e) { MessageBox.Show(e.Message, Globals.ErrorStrings.FunctionControlErrorTitle); } } return(collection); }
private void SetRoomFunctionCalls(string roomName, FunctionCallsCollection functionCalls) { System.Diagnostics.Debug.Assert(roomName != null && roomName != "" && functionCalls != null); if (!RoomNameMap.ContainsKey(roomName)) { throw new DomainModelException("Room could not be found: " + roomName); } RoomNameMap[roomName].FunctionCalls = functionCalls; }
private void PushInheritDataToCode(FunctionCallsCollection inherits) { //assume we have children in the function body if (this.Code.Tokens.Count < 2) { MessageBox.Show("DEBUG ERROR: Missing function body for 'create'. Parser mismatched token children."); return; } //build a list of all inherits that already exist and just need to be changed Dictionary <string, Parser.Token> list = this.Code.GetAllInherits(); List <string> remaining = new List <string>(inherits.CallList.Keys); //edit or remove ihherits that already exist in the code foreach (string codeCall in list.Keys) { foreach (string dataCall in inherits.CallList.Keys) { string temp = codeCall.Trim(); if (dataCall == temp) { //edit currently existsing data within the parsed LPC object if (list[dataCall].Type == Parser.TokenType.InheritCommand) { //do we remove or edit? if (inherits.RemoveFlag.ContainsKey(dataCall)) { //remove list[dataCall].SetTextAsThisToken(ItemModel.InheritRemovalValueReplacer); } } remaining.Remove(dataCall); } } } //now we add the model inherits to the code...maybe foreach (string dataCall in remaining) { //do we add or just move on? if (!inherits.RemoveFlag.ContainsKey(dataCall)) { //we can add it this.Code.AddInherit(dataCall); } } return; }
private string CheckParams(FunctionCallsCollection callsList, string name) { if (name.Contains("inherit") && callsList.CallList.ContainsKey(name)) { if (callsList.CallList[name] == "1") { return("1"); } else { return(null); } } else { if (callsList.CallList.ContainsKey(name)) { return(callsList.CallList[name]); } } return(null); }
public RoomModel(FunctionCallsCollection functionCalls, string fileName, DomainModel model, RoomType type) { FunctionCalls = functionCalls; FileName = fileName; RawFileName = RoomModel.ConvertFullPathToRoomName(fileName); //try loading pre-exiting file first. If you can't, //then create one from the default text file asset string roomPath = model.DomainRootDir + System.IO.Path.DirectorySeparatorChar.ToString() + model.IncludeFile.StripDeadSoulsPath(DeadSouls.Globals.DomainDirectories.Room); string fullFilePath = roomPath + System.IO.Path.DirectorySeparatorChar.ToString() + RawFileName; if (System.IO.File.Exists(fullFilePath)) { Code.LoadLPC(fullFilePath); } else { switch (type) { case RoomType.Normal: { Code.CreateLPCFromScratch(DeadSoulsObjectType.Room); break; } case RoomType.Shop: { Code.CreateLPCFromScratch(DeadSoulsObjectType.Shop); break; } case RoomType.Instance: { Code.CreateLPCFromScratch(DeadSoulsObjectType.InstanceRoom); break; } case RoomType.PoliceStation: { Code.CreateLPCFromScratch(DeadSoulsObjectType.PoliceOffice); break; } case RoomType.JailCell: { Code.CreateLPCFromScratch(DeadSoulsObjectType.JailCell); break; } default: { Code.CreateLPCFromScratch(DeadSoulsObjectType.Room); break; } } //Code.CreateLPCFromScratch(DeadSoulsObjectType.Room); } //PushDataToCode(); }
public bool GenerateFile(ItemSaveType itemPath, string fileSaveName) { bool result = false; using (ProgressModal progress = new ProgressModal(5)) { progress.Show(); if (fileSaveName == null || fileSaveName.Length < 1) { return(false); } progress.UpdateProgressBar(); List <IFunctionControl> controls = this.CompileFunctionControlsList(this.refParentForm); progress.UpdateProgressBar(); FunctionCallsCollection inherits = this.CompileIheritList(controls); progress.UpdateProgressBar(); FunctionCallsCollection functions = this.CompileFunctioCallsList(controls); progress.UpdateProgressBar(); result = this.Item.SaveModelToDisk(functions, inherits, itemPath, fileSaveName); progress.UpdateProgressBar(); } return(result); }
/// <summary> /// Collects all controls that represent an inherit command, and stores their processed /// output in a list of FunctionCall objects. (yeah, I know. It should probably not be /// called a 'FunctionCall' object anymore. Sue me.) /// </summary> /// <param name="controls"></param> /// <returns></returns> public FunctionCallsCollection CompileIheritList(List <IFunctionControl> controls) { FunctionCallsCollection collection = new FunctionCallsCollection(); foreach (IFunctionControl control in controls) { try { //only collect if it represents an inherit command //control enabled state does not matter if (control.ParameterType == FuncParamType.Inherit) { collection.DefineCall(control.FunctionName, control.PullEntry()); if (control.PullEntry() == "0" && !collection.RemoveFlag.ContainsKey(control.FunctionName)) { collection.RemoveFlag.Add(control.FunctionName, true); } if (control.PullEntry() == "1" && collection.RemoveFlag.ContainsKey(control.FunctionName)) { collection.RemoveFlag.Remove(control.FunctionName); //collection.AddHeaderFile(control.RequiredHeader); } } } catch (FunctionControlException e) { MessageBox.Show(e.Message, Globals.ErrorStrings.FunctionControlErrorTitle); } catch (ParserException e) { MessageBox.Show(e.Message, Globals.ErrorStrings.FunctionControlErrorTitle); } } return(collection); }
public bool SaveModelToDisk(FunctionCallsCollection functions, FunctionCallsCollection inherits, ItemSaveType saveType, string fileName) { //ensure item directories exists Stellarmap.DeadSouls.Globals.DomainDirectories.ValidateDirectoriesExist(this.refMVCDomain.DomainRootDir); //determine the path the item will be saved to StringBuilder itemPath = new StringBuilder(this.refMVCDomain.DomainRootDir + "\\"); switch (saveType) { case ItemSaveType.Weapon: { itemPath.Append(this.refMVCDomain.IncludeFile.StripDeadSoulsPath(DeadSouls.Globals.DomainDirectories.Weapon)); break; } case ItemSaveType.Armor: { itemPath.Append(this.refMVCDomain.IncludeFile.StripDeadSoulsPath(DeadSouls.Globals.DomainDirectories.Armor)); break; } case ItemSaveType.Door: { itemPath.Append(this.refMVCDomain.IncludeFile.StripDeadSoulsPath(DeadSouls.Globals.DomainDirectories.Door)); break; } case ItemSaveType.Meal: { itemPath.Append(this.refMVCDomain.IncludeFile.StripDeadSoulsPath(DeadSouls.Globals.DomainDirectories.Meal)); break; } case ItemSaveType.NPC: { itemPath.Append(this.refMVCDomain.IncludeFile.StripDeadSoulsPath(DeadSouls.Globals.DomainDirectories.Npc)); break; } case ItemSaveType.Room: { itemPath.Append(this.refMVCDomain.IncludeFile.StripDeadSoulsPath(DeadSouls.Globals.DomainDirectories.Room)); break; } default: { //default to Objects directory itemPath.Append(this.refMVCDomain.IncludeFile.StripDeadSoulsPath(DeadSouls.Globals.DomainDirectories.Object)); break; } } itemPath.Append("\\" + fileName); if (!itemPath.ToString().EndsWith(Globals.Model.RoomExtension)) { itemPath.Append(Globals.Model.RoomExtension); } //TODO: choose save path based on type return(this.Serialize(itemPath.ToString(), functions, inherits)); }
/// <summary> /// Converts the room model's data back into parsed LPC. /// </summary> private void PushFunctionDataToCode(FunctionCallsCollection functions) { //first, find main function Parser.Token body = this.Code.GetFunctionBody("create"); if (body == null) { MessageBox.Show("DEBUG ERROR: Item model's code failed to update properly. The 'create' function body was not found."); return; } //assume we have children in the function body if (body.Children.Count < 2) { MessageBox.Show("DEBUG ERROR: Missing function body for 'create'. Parser mismatched token children."); return; } //build a list of all function calls that already exist and just need to be changed Dictionary <string, Parser.Token> list = this.Code.GetAllFunctionCalls(body); List <string> remaining = new List <string>(functions.CallList.Keys); //build list of relevant function calls within body foreach (string codeCall in list.Keys) { foreach (string dataCall in functions.CallList.Keys) { if (dataCall == codeCall.Trim()) { //edit currently existsing data within the parsed LPC object if (list[dataCall].Type == Parser.TokenType.FunctionCall) { //make sure hash symbol is removed before adding string[] temp = dataCall.Split(Globals.Generator.FunctionHashSymbol.ToCharArray()); string functionName = temp[0]; //edit exiting function const int FUNCTION_CALL_PARAMS = 0; list[dataCall].SetTextAsTokens(functions.CallList[functionName], FUNCTION_CALL_PARAMS); } remaining.Remove(dataCall); } } } //now deal with all the remaining function calls from //the model that aren't in the LPC parse map yet. List <string> removedFunctions = new List <string>(); foreach (string dataCall in remaining) { /* * const int FUNCTION_BODY = 1; * //make sure hash symbol is removed before adding * string[] temp = dataCall.Split(Globals.Generator.FunctionHashSymbol.ToCharArray()); * string functionName = temp[0]; * * //add functiuons that don't exist within the parsed LPC * //but do exist within the model * body.InsertTextAsTokensEnd("\t" + functionName + "();\n",FUNCTION_BODY); */ const int FUNCTION_BODY = 1; //make sure hash symbol is removed before adding string parameters = functions.CallList[dataCall]; if (parameters.Length > 0 && parameters != null && parameters != "({})" && parameters != "([])" && parameters != "\"\"") { string[] temp = dataCall.Split(Globals.Generator.FunctionHashSymbol.ToCharArray()); string functionName = temp[0]; //add functiuons that don't exist within the parsed LPC //but do exist within the model body.InsertTextAsTokensEnd("\t" + functionName + "();\n", FUNCTION_BODY); } else { removedFunctions.Add(dataCall); } } //loop through again to fill in the parameters for everything we just created list = this.Code.GetAllFunctionCalls(body); //HACK ALERT!!! //when we entered the functions with the hash symbol they used whatever value was tagged onto the end of them //However, now they are using a number count assigned by the 'GetAllFunctionCalls()' which will inevitably make //the results turn sour. So we need to convert all hashed function values to a numeric system, while //also keeing in mind that the first function with a given name is not given a hash symbol by 'GetAllFunctionCalls()'. //Basically we are going to tack on a numbered count after each instance of a function call except the first. Dictionary <string, int> funcHashCount = new Dictionary <string, int>(); foreach (string dataCall in remaining) { string functionKey = dataCall; if (!removedFunctions.Contains(dataCall)) { //hack alert: see above if (functionKey.Contains(Globals.Generator.FunctionHashSymbol)) { string[] temp = functionKey.Split(Globals.Generator.FunctionHashSymbol.ToCharArray()); functionKey = temp[0]; //don't add hash to first instance of a function call if (!funcHashCount.ContainsKey(functionKey)) { funcHashCount.Add(functionKey, 0); } else { funcHashCount[functionKey]++; functionKey = functionKey + Globals.Generator.FunctionHashSymbol + funcHashCount[functionKey]; } } //end hack alert const int FUNCTION_CALL_PARAMS = 0; if (functionKey != null && functionKey.Length > 0 && list[functionKey].Type == Parser.TokenType.FunctionCall) { //make sure hash symbol is removed before adding string[] temp = functionKey.Split(Globals.Generator.FunctionHashSymbol.ToCharArray()); string functionName = temp[0]; list[functionKey].SetTextAsTokens(functions.CallList[dataCall], FUNCTION_CALL_PARAMS); } } //end if not in removed } foreach (string file in functions.AdditionalIncludes) { this.Code.AddInclude(file); } return; }
private void CalculateCost_Click(object sender, EventArgs e) { string agentName = "CreateItemForm->CalculatCost_Click"; List <IFunctionControl> functionControls = this.Manager.CompileFunctionControlsList(this); FunctionCallsCollection functions = this.Manager.CompileFunctioCallsList(functionControls); FunctionCallsCollection inherits = this.Manager.CompileIheritList(functionControls); double HpValue = 0.15; int totalCost = 0; string protections = CheckParams(functions, "SetProtections"); if (protections != null) { foreach (string v in ParserTools.StringIntoMap(protections, agentName).Values) { totalCost += 8 * Convert.ToInt32(v); } } //if total cost is already over 8 (due to armor costs) we know this is an armor so at that //point we will start charging for the armor's hp as well if (totalCost > 8) { string hp = CheckParams(functions, "SetDamagePoints"); if (hp != null) { totalCost += (int)System.Math.Round((double)Convert.ToDouble(hp) * HpValue); } } if (CheckParams(inherits, "inherit LIB_WORN_STORAGE;") != null) { string carry = CheckParams(functions, "SetMaxCarry"); //divide by ten since weights are in hundreths of a pound if (carry != null) { totalCost += 3 * Convert.ToInt32(carry) / 10; } } //divide by ten since weights are in hundreths of a pound string mass = CheckParams(functions, "SetMass"); if (mass != null) { totalCost -= Convert.ToInt32(mass) / 10; } if (CheckParams(inherits, "inherit LIB_SPACESUIT;") != null) { totalCost += 5000; } if (CheckParams(inherits, "inherit LIB_ZURAKIGLOVES;") != null) { totalCost += 250; } this.SetBaseCost.EntryValue = totalCost; return; }
private void CalculateCost_Click(object sender, EventArgs e) { string agentName = "CreateItemForm->CalculatCost_Click"; List <IFunctionControl> functionControls = this.Manager.CompileFunctionControlsList(this); FunctionCallsCollection functions = this.Manager.CompileFunctioCallsList(functionControls); FunctionCallsCollection inherits = this.Manager.CompileIheritList(functionControls); double HpValue = 0.15; int totalCost = 0; //is it a gun? if (CheckParams(inherits, "inherit LIB_FIREARM;") != null) { //check firearm damage string gunDamage = CheckParams(functions, "SetGunClass"); if (gunDamage != null) { totalCost += 10 * Convert.ToInt32(gunDamage); } //reduced melee value string meleeDamage = CheckParams(functions, "SetClass"); if (meleeDamage != null) { totalCost += 2 * Convert.ToInt32(meleeDamage); } //tally up number of damagetypes for gun string damageType = CheckParams(functions, "SetGunDamageType"); if (damageType != null) { foreach (string value in ParserTools.StringIntoORList(damageType, agentName)) { //adds 12 for each type of damage it does totalCost += 12; } } string hp = CheckParams(functions, "SetDamagePoints"); if (hp != null) { totalCost += (int)System.Math.Round((double)Convert.ToDouble(hp) * HpValue); } string accuracy = CheckParams(functions, "SetAccuracy"); if (accuracy != null) { totalCost -= 5 * (100 - Convert.ToInt32(accuracy)); } string accuracyDrop = CheckParams(functions, "SetAccuracyDropoff"); if (accuracyDrop != null) { totalCost -= Convert.ToInt32(accuracyDrop); } } //else, is it ammo? else if (CheckParams(inherits, "inherit LIB_MAGAZINE;") != null) { string damageType = CheckParams(functions, "SetDamageTypeBonus"); if (damageType != null) { foreach (string value in ParserTools.StringIntoORList(damageType, agentName)) { totalCost += 1; } } //we assume that if there is more than one for max ammo, that it is a clip //and if there is only one, it is a round string maxAmmo = CheckParams(functions, "SetMaxAmmo"); if (maxAmmo != null) { int ammo = Convert.ToInt32(maxAmmo); //round based if (ammo == 1) { totalCost += 1; double AccuracyBonusValue = 0.10; double ClassBonusValue = 0.10; string classBonus = CheckParams(functions, "SetClassBonus"); if (classBonus != null) { totalCost += (int)System.Math.Floor((double)Convert.ToDouble(classBonus) * ClassBonusValue); } string accuracyBonus = CheckParams(functions, "SetAccuracyBonus"); if (accuracyBonus != null) { totalCost += (int)System.Math.Floor((double)Convert.ToDouble(accuracyBonus) * AccuracyBonusValue); } } //magazine based else { totalCost += (int)System.Math.Round((double)ammo * (double)0.4f); double AccuracyBonusValue = 0.5; double ClassBonusValue = 0.5; string classBonus = CheckParams(functions, "SetClassBonus"); if (classBonus != null) { totalCost += (int)System.Math.Floor((double)Convert.ToDouble(classBonus) * ClassBonusValue); } string accuracyBonus = CheckParams(functions, "SetAccuracyBonus"); if (accuracyBonus != null) { totalCost += (int)System.Math.Floor((double)Convert.ToDouble(accuracyBonus) * AccuracyBonusValue); } } } } //must be a regular item, maybe a weapon? else { //otherwise check melee at regular value string meleeDamage = CheckParams(functions, "SetClass"); if (meleeDamage != null) { totalCost += 8 * Convert.ToInt32(meleeDamage); } //tally up number of damagetypes for gun string damageType = CheckParams(functions, "SetDamageType"); if (damageType != null) { foreach (string value in ParserTools.StringIntoORList(damageType, agentName)) { //adds 12 for each type of damage it does totalCost += 12; } } //is it a weapon? if (Convert.ToInt32(meleeDamage) > 1) { string hp = CheckParams(functions, "SetDamagePoints"); if (hp != null) { totalCost += (int)System.Math.Round((double)Convert.ToDouble(hp) * HpValue); } } } if (CheckParams(inherits, "inherit LIB_STORAGE;") != null) { string carry = CheckParams(functions, "SetMaxCarry"); //divide by ten since weights are in hundreths of a pound if (carry != null) { totalCost += 2 * Convert.ToInt32(carry) / 10; } } //divide by ten since weights are in hundreths of a pound string mass = CheckParams(functions, "SetMass"); if (mass != null) { totalCost -= Convert.ToInt32(mass) / 10; } this.SetBaseCost.EntryValue = totalCost; return; }
public void DisplayModel(string roomFileName, FunctionCallsCollection functionCalls) { }