bool ActionDecision(ConditionalItem decision) { bool actionMade = false; if (ValidAction(decision)) { switch (decision.action) { case Actions.ATTACK: currTarget = enemyList[0].transform.position; break; case Actions.MOVE_BACK: currTarget = this.transform.position + backMovementMod; break; case Actions.MOVE_FORWARD: currTarget = this.transform.position + -backMovementMod; break; case Actions.MOVE_ENEMY: currTarget = enemyList[0].transform.position; break; case Actions.REST: break; } actionMade = true; currNote = decision.note; currAction = decision.action; } return(actionMade); }
public void SetVals(ConditionalItem newItem) { cond1.varCheck.value = (int)newItem.cond1Ind; cond2.varCheck.value = (int)newItem.cond2Ind; cond1.spin.Value = newItem.cond1Val; cond2.spin.Value = newItem.cond2Val; condBool.value = newItem.greater ? 0 : 1; actionDropdown.value = (int)newItem.action; noteDropdown.value = (int)newItem.note; }
/// <summary> /// Helper method to find the correct item based on it's condition test. /// If none match the condition, then the default item is returned. /// </summary> /// <param name="obj"></param> /// <returns></returns> private IMappedItem FindItem(T obj) { ConditionalItem <T> item = Items.FirstOrDefault(entry => entry.ConditionTest(obj)); if (item != null) { return(item.Item); } return(DefaultItem); }
void Update() { tempItem = new ConditionalItem(); tempItem.action = (ConstFile.Actions)actionDropdown.value; tempItem.cond1Ind = (ConstFile.ConditionOptions)cond1.varCheck.value; tempItem.cond2Ind = (ConstFile.ConditionOptions)cond2.varCheck.value; tempItem.cond1Val = cond1.currVal; tempItem.cond2Val = cond2.currVal; tempItem.greater = condBool.value == 0 ? true : false; tempItem.note = (ConstFile.Notes)noteDropdown.value; }
/* * void OnDestroy() * { * * if (this.enabled) * { * DebugPanel.Log("OnDestroyEnabled", "Unit" + id, "uh oh"); * DebugPanel.Log("Dead", "Unit" + id, string.Format("{0}: {1}", Time.time, true)); * GameManager.AddUnit -= EnemyAdd; * GameManager.RemoveUnit -= EnemyRemove; * MusicManager.units.Remove((UnitScript)this); * GameManager.RemoveDeadUnit(team, this.gameObject, currType); * } * } * * void OnDisable() * { * DebugPanel.Log("Dead", "Unit" + id, string.Format("{0}: {1}", Time.time, true)); * GameManager.AddUnit -= EnemyAdd; * GameManager.RemoveUnit -= EnemyRemove; * MusicManager.units.Remove((UnitScript)this); * GameManager.RemoveDeadUnit(team, this.gameObject, currType); * } */ protected bool ValidAction(ConditionalItem item) { float firstVal = 0, secondVal = 0; switch (item.cond1Ind) { case CondOptions.ENEMY_DISTANCE: if (enemyList.Count > 0) { firstVal = ArenaGrid.GridDistance(this.transform.position, enemyList[0].transform.position); } else { firstVal = float.MaxValue; } break; case CondOptions.ENERGY: firstVal = energy; break; case CondOptions.VALUE: firstVal = item.cond1Val; break; } switch (item.cond2Ind) { case CondOptions.ENEMY_DISTANCE: if (enemyList.Count > 0) { secondVal = ArenaGrid.GridDistance(this.transform.position, enemyList[0].transform.position); } else { secondVal = float.MaxValue; } break; case CondOptions.ENERGY: secondVal = energy; break; case CondOptions.VALUE: secondVal = item.cond2Val; break; } bool retVal = item.greater ? firstVal > secondVal : firstVal < secondVal; return(retVal); }
protected void Strat(List <ConditionalItem> AI) { bool actionMade = false; for (int i = 0; i < AI.Count; i++) { ConditionalItem decision = AI[i]; actionMade = ActionDecision(decision); if (actionMade) { break; } } if (!actionMade) { currAction = Actions.REST; currNote = ConstFile.Notes.EIGHTH; } DebugPanel.Log("Qued Action", "Unit" + id, string.Format("{0}:{1} | {2}", Time.time, currAction, currNote)); }
public void GenericSaveList() { List <ConditionalItem> tempList = new List <ConditionalItem>(); ConditionalItem condItem = new ConditionalItem(); for (int i = 0; i < 10; i++) { condItem = new ConditionalItem(); condItem.cond1Val = i; condItem.cond2Val = i; tempList.Add(condItem); } SaveUtil.SaveList <ConditionalItem>(tempList, TEST_KEY); List <ConditionalItem> loadedList = SaveUtil.LoadList <ConditionalItem>(TEST_KEY); Assert.AreEqual(tempList.Count, loadedList.Count); for (int i = 0; i < tempList.Count; i++) { Assert.AreEqual(tempList[i].GetSentence(), loadedList[i].GetSentence()); } PlayerPrefs.DeleteKey(TEST_KEY); }
public void SetData(ConditionalItem newItem) { item = newItem; }