diff options
Diffstat (limited to 'src/EventRunner.php')
| -rw-r--r-- | src/EventRunner.php | 46 | 
1 files changed, 42 insertions, 4 deletions
diff --git a/src/EventRunner.php b/src/EventRunner.php index e4bdb40..439cca5 100644 --- a/src/EventRunner.php +++ b/src/EventRunner.php @@ -121,7 +121,7 @@ class EventRunner      $tickMultiplier = $diff->i + 60*$diff->h + 60*24*$diff->d;      if ($tickMultiplier > 0) { -      $villages = DB::fetch(Village::class, 'select id,wood,clay,iron,food from villages'); +      $villages = DB::fetch(Village::class, 'select id,wood,clay,iron,food,satisfaction from villages');        foreach ($villages as $village) {          /**@var Village $village*/ @@ -142,23 +142,61 @@ class EventRunner            }          } +        $foodIncrementor = 0; +          $resources = [];          foreach ($resourceGenerators as $generator) { +          /**@type ResourceGenerator $generator*/ + +          if ($generator->type === 'Farm') { +            $foodIncrementor = $generator->getResourceIncrementor(); +          } +            $village->{$generator->resourceType} = min( -            $village->{$generator->resourceType} + ($generator->getResourceIncrementor() * $tickMultiplier), +            max( +              $village->{$generator->resourceType} + ($generator->getResourceIncrementor() * $tickMultiplier), +              0 +            ),              $storage->getResourceCapacity($generator->resourceType)            );          } +        $populationDemand = Village::getPopulationDemand($village->id); +        if ( +          $foodIncrementor < 0 && +          (abs($village->food / $foodIncrementor) < $_ENV['SATISFACTION_FOOD_THRESHOLD'] || $village->food < $populationDemand) +        ) { +          $village->satisfaction = min(max($village->satisfaction - (1 * $tickMultiplier), 0), 100); +        } else if ($foodIncrementor > 0) { +          $village->satisfaction = min(max($village->satisfaction + (1 * $tickMultiplier), 0), 100); +        } +          DB::query( -          'update villages set wood=:wood, clay=:clay, iron=:iron, food=:food where id=:id', -          ['wood' => $village->wood, 'clay' => $village->clay, 'iron' => $village->iron, 'food' => $village->food, 'id' => $village->id] +          'update villages set wood=:wood, clay=:clay, iron=:iron, food=:food, satisfaction=:satisfaction where id=:id', +          [ +            'wood' => $village->wood, 'clay' => $village->clay, 'iron' => $village->iron, 'food' => $village->food, +            'satisfaction' => $village->satisfaction, +            'id' => $village->id, +          ]          );        }        DB::query('delete from system where key=:key', ['key' => 'last_resource_tick']);        $lastResourceTickMinute = (new \DateTime((new \DateTime())->format('Y-m-d H:i')))->format('c');        DB::query('insert into system (key,value) VALUES (:key,:value)', ['key' => 'last_resource_tick', 'value' => json_encode($lastResourceTickMinute)]); + + +      // Satisfaction + +      // TODO: < 75 => resource increment reduction +      // TODO: < 50 => support units go home +      // TODO: < 30 => home units walk away +      //       record which units +      //       => after X units => create new NPC village +      // +      // TODO: > 50 home units come back +      //       > 75 resource increment normal +      //       > 95 resource increment higher?      }    }  }  | 
