001package com.fs.starfarer.api.impl.campaign.ghosts;
002
003import java.util.ArrayList;
004import java.util.List;
005
006import com.fs.starfarer.api.Global;
007
008public class BaseGhostBehavior implements GhostBehavior {
009        protected float duration;
010        protected List<GhostBehaviorInterrupt> interrupts = new ArrayList<GhostBehaviorInterrupt>();
011        
012        public BaseGhostBehavior(float duration) {
013                this.duration = duration;
014        }
015
016        public boolean isDone() {
017                return duration <= 0f;
018        }
019
020        public void advance(float amount, SensorGhost ghost) {
021                float days = Global.getSector().getClock().convertToDays(amount);
022                duration -= days;
023                
024                for (GhostBehaviorInterrupt curr : interrupts) {
025                        curr.advance(amount, ghost, this);
026                        if (curr.shouldInterruptBehavior(ghost, this)) {
027                                end();
028                                break;
029                        }
030                }
031        }
032        
033        public void end() {
034                duration = 0f;
035        }
036        
037        public void addInterrupt(GhostBehaviorInterrupt interrupt) {
038                interrupts.add(interrupt);
039        }
040}