Exemple #1
0
 public override ActionResult Run(IntelligenceController controller, float deltaTime)
 {
     PatrolPath path = null;
     if (controller.GetMemoryValue(Intelligence.SpecialPathIdentifier, out path))
     {
         int currentIndex = 0;
         if (!controller.GetMemoryValue(Intelligence.SpecialPathIndexIdentifier, out currentIndex))
         {
             controller.SetMemoryValue(Intelligence.SpecialPathIndexIdentifier, 0);
         }
         EntityMover.MoveResult result = controller.Owner.MoveTo(path.points[currentIndex].position);
         if (result == EntityMover.MoveResult.ReachedTarget)
         {
             currentIndex++;
             if (currentIndex >= path.points.Count)
             {
                 currentIndex = 0;
                 controller.SetMemoryValue(Intelligence.SpecialPathIndexIdentifier, 0);
                 return ActionResult.Success;
             }
             controller.SetMemoryValue(Intelligence.SpecialPathIndexIdentifier, currentIndex);
         }
         return ActionResult.Running;
     }
     return ActionResult.Failed;
 }
Exemple #2
0
 public override ActionResult Fire(IntelligenceController controller)
 {
     Entity t = null;
     switch (Type)
     {
         case TargetType.Human:
             t = GameWorld.Instance.GetNearestHuman(controller.Owner.transform.position, targetClassification);
             break;
         case TargetType.Fungus:
             t = GameWorld.Instance.GetNearestFungusNode(controller.Owner.transform.position);
             break;
         case TargetType.PoliceStation:
             t = GameWorld.Instance.GetNearestPoliceStation(controller.Owner.transform.position);
             break;
     }
     if (t && Mathf.Sqrt(AstarMath.SqrMagnitudeXZ(controller.Owner.transform.position, t.transform.position)) <= range)
     {
         if (checkLOS && !GameWorld.Instance.HasLineOfSight(controller.Owner, t))
         {
             return ActionResult.Failed;
         }
         if (saveVar)
         {
             controller.SetMemoryValue(storageVar, t);
         }
         return ActionResult.Success;
     }
     return ActionResult.Failed;
 }
Exemple #3
0
 public override ActionResult Fire(IntelligenceController controller)
 {
     Vector3 pos;
     if (posVarSource == PositionSource.Self)
     {
         pos = controller.Owner.transform.position;
     }
     else
     {
         if (posVarName.Length < 1) { return ActionResult.Failed; }
         if (!controller.GetMemoryValue(posVarName, out pos))
         {
             Entity e;
             if (!controller.GetMemoryValue(posVarName, out e))
             {
                 return ActionResult.Failed;
             }
             pos = e.transform.position;
         }
     }
     FungusNode node = GameWorld.Instance.SpawnFungusNode(pos);
     if (saveAsVar)
     {
         if (saveVarName.Length > 0)
         {
             controller.SetMemoryValue(saveVarName, node);
             return ActionResult.Success;
         }
         return ActionResult.Failed;
     }
     return ActionResult.Success;
 }
Exemple #4
0
 public override ActionResult Fire(IntelligenceController controller)
 {
     if (varName.Length < 1) { return ActionResult.Failed; }
     if (target == TargetType.Self)
     {
         controller.SetMemoryValue(varName, controller.Owner.transform.position);
         return ActionResult.Success;
     }
     Entity e;
     if (controller.GetMemoryValue(targetVarName, out e))
     {
         controller.SetMemoryValue(varName, e.transform.position);
         return ActionResult.Success;
     }
     return ActionResult.Failed;
 }
Exemple #5
0
 public override ActionResult Fire(IntelligenceController controller)
 {
     var modID = controller.Owner.ApplySpeedMod(type, controller.Owner, timeout);
     if (saveAsVar)
     {
         controller.SetMemoryValue(varName, modID);
     }
     return ActionResult.Success;
 }
Exemple #6
0
 public override ActionResult Run(IntelligenceController controller, float deltaTime)
 {
     repeated = false;
     REPEAT:
     if (currentWaitTime > 0) { currentWaitTime = UnityEngine.Mathf.Clamp(currentWaitTime - deltaTime, 0, currentWaitTime); return ActionResult.Running; }
     PatrolPath path = null;
     if (controller.GetMemoryValue(Intelligence.PathIdentifier, out path))
     {
         int currentIndex = 0;
         if (!controller.GetMemoryValue(Intelligence.PathIndexIdentifier, out currentIndex))
         {
             controller.SetMemoryValue(Intelligence.PathIndexIdentifier, 0);
         }
         PatrolPath.PatrolPoint currentPoint = path.points[currentIndex];
         EntityMover.MoveResult result = controller.Owner.MoveTo(currentPoint.position);
         if (result == EntityMover.MoveResult.ReachedTarget)
         {
             if (!ignorePathConfiguration)
             {
                 switch (currentPoint.action)
                 {
                     case PatrolPath.PatrolPointActions.Wait:
                         currentWaitTime = currentPoint.waitTime;
                         break;
                     case PatrolPath.PatrolPointActions.ChangePath:
                         if (UnityEngine.Random.Range(0, 100) > currentPoint.actionProbability) { break; }
                         PatrolPath linkedPath = currentPoint.linkedPath;
                         if (linkedPath != null)
                         {
                             controller.LoadPath(linkedPath);
                             controller.SetMemoryValue(Intelligence.PathIndexIdentifier, linkedPath.GetNearestPatrolPointIndex(controller.Owner.transform.position));
                             return ActionResult.Running;
                         }
                         break;
                     case PatrolPath.PatrolPointActions.ExecuteFunction:
                         if (UnityEngine.Random.Range(0, 100) > currentPoint.actionProbability) { break; }
                         switch (currentPoint.target)
                         {
                             case PatrolPath.PatrolPoint.FunctionTarget.NPC:
                                 controller.Owner.BroadcastMessage(currentPoint.functionName, UnityEngine.SendMessageOptions.RequireReceiver);
                                 break;
                             case PatrolPath.PatrolPoint.FunctionTarget.PatrolPath:
                                 path.BroadcastMessage(currentPoint.functionName, UnityEngine.SendMessageOptions.RequireReceiver);
                                 break;
                         }
                         break;
                 }
             }
             currentIndex++;
             if (currentIndex >= path.points.Count)
             {
                 currentIndex = 0;
             }
             controller.SetMemoryValue(Intelligence.PathIndexIdentifier, currentIndex);
             if (!repeated)
             {
                 repeated = true;
                 goto REPEAT;
             }
         }
         return ActionResult.Running;
     }
     return ActionResult.Failed;
 }
Exemple #7
0
 public override ActionResult Fire(IntelligenceController controller)
 {
     controller.SetMemoryValue(varName, null);
     return ActionResult.Success;
 }
Exemple #8
0
 public override ActionResult Fire(IntelligenceController controller, object value = null)
 {
     controller.SetMemoryValue(saveName, value);
     return ActionResult.Success;
 }
Exemple #9
0
 public override ActionResult Fire(IntelligenceController controller, object value = null)
 {
     Message m = value as Message;
     if (m == null) { return ActionResult.Failed; }
     if (m.type != handledType) { return ActionResult.Failed; }
     if (savePosition)
     {
         controller.SetMemoryValue(varName, m.position);
     }
     if (saveSender)
     {
         controller.SetMemoryValue(senderVarName, m.sender);
     }
     if (action)
     {
         action.Fire(controller, value);
     }
     return ActionResult.Success;
 }