DTOs
Add the following code to the Objectives class:
public struct ClaimRequest
{
public int id;
}
public struct ClaimResponse
{
public bool isRewardGranted; }
Controller
Add the following code to the ObjectivesController class:
public void claimReward(int id)
{
Debug.Log(“Claiming reward for objective ” + id); var request = new Objectives.ClaimRequest(); request.id = id;
interactor.doClaim(request);
}
Interactor
Add the following code to the ObjectivesInteractor class:
public void doClaim(Objectives.ClaimRequest request)
{
var response = new Objectives.ClaimResponse();
{
//invalid index
if (request.id >= this.fetchedObjectives.Length)
response.isRewardGranted = false; this.presenter.presentClaim(response); return;
}
//max step not reached
if (this.fetchedObjectives[request.id].currentStep !=
this.fetchedObjectives[request.id].numberOfSteps)
{
response.isRewardGranted = false; this.presenter.presentClaim(response); return;
}
var reward = this.fetchedObjectives[request.id].reward;
LocalMoneyWorker.Instance.Sell(reward, delegate(int amount) {
true);
//everything is fine, we can update claim status //fetchedObjectives[request.id].isRewardClaimed = true; ObjectivesWorker.UpdateStatus(request.id, fetchedSet,
//since we flushed data we fetch objectives again
var fetchRequest = new Objectives.FetchRequest(); fetchRequest.numberOfObjectives = numberOfObjectives; fetchRequest.set = fetchedSet;
doFetch(fetchRequest);
//if all Game Objectives are complete and claimed, we should autoflush
if (fetchedSet == Objectives.ObjectiveSet.Game)
{
bool shouldAutoFlush = true;
foreach (var objective in fetchedObjectives) {
if (false == objective.isRewardClaimed)
{
shouldAutoFlush = false;
} }
if (shouldAutoFlush)
{
var flushRequest = new Objectives.FlushRequest();
doFlush(flushRequest); }
}
response.isRewardGranted = true;
this.presenter.presentClaim(response); } );
}
Presenter
Add the following code to the ObjectivesPresenter class:
public void presentClaim(Objectives.ClaimResponse response)
{
if (response.isRewardGranted)
{
NotifierPresenter.Instance
.PerformInstantaneousRequest("Cash Earned !"); }
else {
NotifierPresenter.Instance
.PerformInstantaneousRequest("Hum ... Cannot add more cash !");
} }