Quest counter and messaging
Posted: Thu Oct 31, 2019 5:52 pm
Hey Tony! I worked for a while with messaging and quests, but I don't quite get it. I want to do the following:
1) When a player gets an item "Cheese burger", set a counter in any quests that has a counter called "Cheese burger" to the amount of the player inventory.
I'm doing this when item is added, and it's received by my "QuestItemMessage" script below.
I thought the setting in the image below would make it update the counter when it got the SetCount message, but it doesn't. It confuses me that it says "Set To Parameter" (which is "Cheese burger"). I want it to set to the value, which is "count" in the above code sample. How does this work?
2) When this happens, set a quest node successful (Condition: Counter: Cheese burger >= 1) I guess would work, if I could just set the counter.
3) When the quest is completed, add 1000 credits, and I solved this with a custom QuestAction.
So basically it's just (1) i need help with However it might not be the optimal way to do it like this, if there are hundreds of quest. So maybe there's a better way to have a condition that checks if the player has a specific amount of an item?
Thank you in advance!
-niclas
PS: A small "display bug" on CounterQuestCondition:117. In the debug log it says "QuestMachine" instead of "Quest Machine" that most other script to. Just a minor issue Also QuestSubasset:145 has this.
1) When a player gets an item "Cheese burger", set a counter in any quests that has a counter called "Cheese burger" to the amount of the player inventory.
I'm doing this when item is added, and it's received by my "QuestItemMessage" script below.
Code: Select all
MessageSystem.SendMessage(this, "SetCount", item.name, count);
Code: Select all
public class QuestItemMessage : MonoBehaviour, IMessageHandler {
private void OnEnable() {
MessageSystem.AddListener(this, "QuestItem", string.Empty);
MessageSystem.AddListener(this, "SetCount", string.Empty);
}
private void OnDisable() {
MessageSystem.RemoveListener(this);
}
public void OnMessage(MessageArgs messageArgs) {
switch (messageArgs.message) {
case "SetCount":
SetQuestCounter(messageArgs.parameter,BlueGoo.Utils.Utils.ParseInt(messageArgs.values[0].ToString()));
Debug.Log("SetCount: " + messageArgs.parameter + " " + messageArgs.values[0]);
break;
case "QuestItem":
Debug.Log("QuestItem: " + messageArgs.parameter + " " + messageArgs.values[0]);
break;
}
}
private void SetQuestCounter(string counterName, int value) {
foreach (var kvp in QuestMachine.GetAllQuestInstances()) {
var quests = kvp.Value;
if (quests == null) continue;
for (int i = 0; i < quests.Count; i++) {
var quest = quests[i];
if (quest == null) continue;
for (int j = 0; j < quest.counterList.Count; j++) {
if (quest.counterList[j].name.ToString() == counterName) {
quest.counterList[j].currentValue = value;
}
}
}
}
}
}
2) When this happens, set a quest node successful (Condition: Counter: Cheese burger >= 1) I guess would work, if I could just set the counter.
3) When the quest is completed, add 1000 credits, and I solved this with a custom QuestAction.
So basically it's just (1) i need help with However it might not be the optimal way to do it like this, if there are hundreds of quest. So maybe there's a better way to have a condition that checks if the player has a specific amount of an item?
Thank you in advance!
-niclas
PS: A small "display bug" on CounterQuestCondition:117. In the debug log it says "QuestMachine" instead of "Quest Machine" that most other script to. Just a minor issue Also QuestSubasset:145 has this.
Code: Select all
if (Debug.isDebugBuild) Debug.LogWarning("QuestMachine: QuestCounterCondition.OnCounterChanged(" + StringField.GetStringValue(counter.name) + " = " + counter.currentValue + "): requiredCounterValue field is null. Please contact the developer.", quest);