示例#1
0
    // Use this for initialization
    void Start()
    {
        if (represents.name != "Wall")
        {
            GetComponent <Collider2D>().enabled = false;
        }
        sprRenderer = GetComponent <SpriteRenderer>();
        // sprRenderer.sprite = represents.texture;
        sprRenderer.sortingLayerName = "Default";
        sprRenderer.sortingOrder     = -10;

        /*tierVisualizer = new GameObject();
         * tierVisualizer.transform.parent = transform;
         * tierVisualizer.transform.localPosition = new Vector3(-0.5f, 0.5f);
         * vizualizerMesh = tierVisualizer.AddComponent<TextMesh>();
         * vizualizerMesh.text = tileTier.ToString();
         * vizualizerMesh.color = Color.green;*/


        this.visited = false;
        this.heading = null;

        RoomManager.instance.setTile((int)transform.position.x, (int)transform.position.y, this);

        positionInWorld = new Vector2Int((int)transform.position.x, (int)transform.position.y);
        this.y          = positionInWorld.y;
        this.x          = positionInWorld.x;
    }
示例#2
0
 // Update is called once per frame
 void Update()
 {
     if (!hasgonethrough)
     {
         hasgonethrough = true;
         for (int k = 0; k < enemySpawns.Length; k++)
         {
             for (int i = 0; i < enemySpawns[k]; i++)
             {
                 ArrayList  spawnableTiles = AiManager.instance._aiSystem.GetTilesByTier(k + 1);
                 int        randomTile     = Random.Range(0, spawnableTiles.Count);
                 TileObject targetPosition = (TileObject)spawnableTiles[randomTile];
                 for (int j = 0; j < usedTiles.Count; j++)
                 {
                     if (targetPosition.GetPosition() == (Vector2)usedTiles[j])
                     {
                         randomTile     = Random.Range(0, spawnableTiles.Count);
                         targetPosition = (TileObject)spawnableTiles[randomTile];
                         j = 0;
                     }
                 }
                 GameObject newEntity = Instantiate(enemyTiers[k], targetPosition.GetPosition(), Quaternion.identity);
                 AiManager.AddAiEntity(newEntity.GetComponent <AiEntity>());
                 AiEntity ae = newEntity.GetComponent <AiEntity>();
                 ae.SetCurrentTile(targetPosition);
                 ae.SetPath(AiManager.instance._aiSystem.CalculateRandomPathByTier(targetPosition.GetPosition(), k + 1));
                 usedTiles.Add(targetPosition.GetPosition());
             }
         }
     }
 }
示例#3
0
 private void doctorCanInspect(AiEntity d, AiEntity t)
 { // doctor
     if (Vector2.Distance(d.transform.position, t.transform.position) < 1.5f)
     {
         StartCoroutine(d.WaitForInspection());
         StartCoroutine(t.WaitForInspection());
     }
 }
示例#4
0
 private void OnErrorInPath(AiEntity e)
 {
     if (e.GetCurrentTile() != null)
     {
         e.SetPath(_aiSystem.CalculateRandomPathByTier(e.GetCurrentTile().GetPosition(), e.getEntityInfo().Tier));
         return;
     }
     e.SetPath(_aiSystem.CalculateRandomPathByTier(new Vector2(1, 1), e.getEntityInfo().Tier));
 }
示例#5
0
    private void OnDoneInspection(AiEntity e)  // doctor
    {
        e.SetPath(_aiSystem.CalculateRandomPathByTier(e.GetCurrentTile().GetPosition(), e.getEntityInfo().Tier));

        if (e.getEntityInfo().IsDoctor)
        {
            e.OnAtTile -= instance.OnAtTile;
        }
    }
示例#6
0
    private void getPath(AiEntity e)
    {
        if (e.GetCurrentTile() == null)
        {
            return;
        }

        // for normal calulate path to random tile
        e.SetPath(_aiSystem.CalculateRandomPathByTier(e.GetCurrentTile().GetPosition(), e.getEntityInfo().Tier));
    }
示例#7
0
    private AiEntity getSickEntityInRange(AiEntity e)
    {
        ArrayList list = new ArrayList();

        for (int i = 0; i < _aiEntitys.Count; i++)
        {
            if (!((AiEntity)_aiEntitys[i]).getEntityInfo().IsDoctor&& Vector2.Distance(e.transform.position, ((AiEntity)_aiEntitys[i]).transform.position) < 10)
            {
                list.Add(_aiEntitys[i]);
            }
        }

        return((AiEntity)list[UnityEngine.Random.Range(0, list.Count - 1)]);
    }
示例#8
0
    static public void AddAiEntity(AiEntity e)
    {
        instance._aiEntitys.Add(e);

        e.OnEndOfPath      += instance.OnEndOfPath;
        e.OnErrorInPath    += instance.OnErrorInPath;
        e.OnDoneInspection += instance.OnDoneInspection;

        // doctor
        if (e.getEntityInfo().IsDoctor)
        {
            e.OnStartInspection = instance.OnStartInspection;
        }
    }
示例#9
0
    public void spawnNewDoctor()
    {
        ArrayList  spawnableTiles = AiManager.instance._aiSystem.GetTilesByTier(doctor.GetComponent <AiEntity>().getEntityInfo().Tier);
        int        randomTile     = Random.Range(0, spawnableTiles.Count);
        TileObject targetPosition = (TileObject)spawnableTiles[randomTile];

        GameObject newEntity = Instantiate(doctor, targetPosition.GetPosition(), Quaternion.identity);

        AiManager.AddAiEntity(newEntity.GetComponent <AiEntity>());
        AiEntity ae = newEntity.GetComponent <AiEntity>();

        ae.SetCurrentTile(targetPosition);
        ae.SetPath(AiManager.instance._aiSystem.CalculateRandomPathByTier(targetPosition.GetPosition(), doctor.GetComponent <AiEntity>().getEntityInfo().Tier));
    }
示例#10
0
    private void OnStartInspection(AiEntity e)
    {
        if (e.getEntityInfo().IsDoctor)
        {
            if (e.getTarget() == null)
            {
                e.setTarget(this.getSickEntityInRange(e));
            }
            else
            {
                this.doctorCanInspect(e, e.getTarget());
            }

            e.SetPath(_aiSystem.CalulatePathTo(e.GetCurrentTile().GetPosition(), e.getTarget().GetCurrentTile().GetPosition()));
            e.OnAtTile += instance.OnAtTile;
        }
    }
示例#11
0
    private void OnAtTile(AiEntity e, TileObject t)
    { // doctor
        if (e.getEntityInfo().IsDoctor)
        {
            if (e.getTarget() == null)
            {
                e.setTarget(this.getSickEntityInRange(e));
            }
            else
            {
                this.doctorCanInspect(e, e.getTarget());
            }


            if (e.GetCurrentTile().GetPosition() == e.getTarget().GetCurrentTile().GetPosition())
            {
                return;
            }
            e.SetPath(_aiSystem.CalulatePathTo(e.GetCurrentTile().GetPosition(), e.getTarget().GetCurrentTile().GetPosition()));
        }
    }
示例#12
0
    public IEnumerator WaitForInspection()
    {
        print("wait");
        isInspecting = true;
        yield return(new WaitForSeconds(5.0f));

        isInspecting = false;
        if (OnDoneInspection != null)
        {
            OnDoneInspection(this);
        }
        this.target = null;
        if (_entityInfo.IsDoctor)
        {
            if (UnityEngine.Random.Range(0, 100) < 40)
            {
                AiManager.instance.spawnNewDoctor();
            }
            StartCoroutine(doctorSearch());
        }
    }
示例#13
0
 private void OnEndOfPath(AiEntity e)
 {
     this.getPath(e);
 }
示例#14
0
 static public void SetNewRandomPath(AiEntity e)
 {
     e.SetPath(instance._aiSystem.CalculateRandomPathByTier(e.GetCurrentTile().GetPosition(), e.getEntityInfo().Tier));
 }
示例#15
0
 private void Awake()
 {
     ai = GetComponent<AiEntity>();
 }
示例#16
0
 public void setTarget(AiEntity t)
 {
     target = t;
 }