Should the "Collect" goal have a "type" option in addition to specific targets?

I might just be mis-understanding how to use the existing Collect goal, but it seems like there should be an option to specify a type of object rather than an individual object’s id? For instance, if you wanted to make a goal of collecting 5 of the same type of object, you could create a “collect” goal and then list all of the items as “targets”. What would be better in that situation is to be able to specify a “type” of object, like sword or mushroom and a “how many”. As it stand right now, adding a “how many” attribute with a value other than 1 seems to make the goal impossible (haven’t really traced through to see why that is). Without the “how many” attribute it requires all specified items to be collected.

The main problem is that if you want to collect lots of objects, then you have to list all of items individually as targets instead of just saying how many you want collected.

As a non-expert in coffeescript, I’m thinking something like: ( codecombat / app / lib / world / GoalManager.coffee )

checkCollected: (goalID, who, targets, thangID, itemID, frameNumber) ->
    return unless itemID in targets
    return unless thangID in who
    @updateGoalState(goalID, thangID, 'collected', frameNumber)

becomes

checkCollected: (goalID, who, targets, thangID, item, frameNumber) ->
    return unless item.id in targets or item.type in targets
    return unless thangID in who
    @updateGoalState(goalID, thangID, 'collected', frameNumber)

Edit: I made a mistake in how I described the issue originally. I think the above is now correct.

How would you suggest the collecting goes about then? Greedily choosing the nearest item and collecting that first? You might not always want collection in that order.

Well, at the moment it looks like the “Kill” and “Save” goals allow for either specifying individual unit IDs to kill or save, or specifying a team (eg “Kill any 3 ogres”).

It would be nice to have the option of either specifying individual items to collect, or just giving a quota for a particular category. It would open up some new options for level designers.

I think you might be on to something, but how about this–until we have a few more use cases that confirm this is a good addition to the goals, we can think of other ways around it. For example, collecting gold, the gold accumulates and then you can use it to build things or perhaps win the level (with a new Component). Is there a particular level you want to make where this won’t work still?

Well, I have a level named “Harvest Time” that I haven’t published yet. (Can the admins still see it? If not I guess I can publish it even though it isn’t ready to go yet.) The idea is for a peasant to harvest a field of 100 mushrooms (for lack of a better crop thang) laid out in a grid. The goal is for the player to use loops to do this with very little code compared to programming the peasant with each waypoint as an individual line of code.

Unfortunately, the way things stand I think I would have to list all 100 mushroom IDs in the Collect goal rather than just saying I want all items of type “Mushroom” to be collected.

OK, just for kicks, I tried adding all 100 mushrooms as targets for the goal. Now collecting any of the mushrooms triggers victory. I thought I read somewhere that if you don’t define the “howMany” attribute for a goal, then it would require all of the listed targets.

The level is published so people can take a look and let me know if I’m doing this wrong.


Ah, I see. The “How Many” is, in this case, applying to the Peasant instead of the Mushrooms.

I think we will need some more work on the GoalManager to support this kind of thing. It’s not quite enough to add the item.type check, because the GoalManager needs to start keeping track of how many items of a given type there are, and then it also needs to be able to apply “How Many” to the targets instead of just the who (like it applies to the other goal types).

I’ve added an issue for this over here: https://github.com/codecombat/codecombat/issues/744

Until we are able to add that (or if you want to take a crack at it), one workaround would be to have another Thang checking how many Mushrooms are left and ending the world with a goal once a set number of Mushrooms have been collected. See Alexandru’s code for the Coin Generator 9000’s Programmable chooseAction() that sets a custom goal to success: http://codecombat.com/editor/level/resource-gathering-multiplayer

I ran into a similar problem with my new level where i needed a custom goal, so I created a new method : setGoalState. Now for example you can only create the goal just for the user to see what to do , and give it an ID . To trigger it you can have an invisible thang for ex which verifies specific goal conditions you want and call the method : this.setGoalState(ID,“success”); . Also you can set a wordEndsAfter property for the goal so when it’s triggered the level will end.

Haha almost perfect sync Nick

Just to follow up on this, I altered the level to use a custom goal instead. A few observations in case someone else wants to do this:

  1. You’ll need an extra Thang to be programmable in order to check progress and set goal states. Just set the permissions for that Thang’s “chooseAction” method to empty. Right now a Thang can’t be programmable without being selectable, so that Thang will show up as a non-controllable unit in the unit list. I did my best to find some reason for that unit to be standing around as far as the level theme goes. This Thang will also need the “Acts” component (I deleted it by mistake and was frustrated for a while as to why my goal states wouldn’t trigger).

  2. I got very sluggish behavior when I had loops involved in checking goal progress. Putting a little bit of effort into spotting a much more efficient progress check really improved level performance.

You can see the finished level here:

Nice work on this level, and sorry it took so much effort to work around the collection limitation. I think if you added a Guide to the level with any hints if people get stuck, then it’d be ready to publish in the user-created levels section–want to add that?

I’ve added a few sort of vague hints to the Guide. Do you think I should have something more specific than what I have there?

Did you save a new version? I don’t see anything in the Harvest Time guide yet.

Regardless, I’ll push it live and send it to some adventurers!

Weird, it was gone when I went back to look just now. I tried adding the hint again, so it should be up now…