public AI(string aiName, List <KeyValuePair <string, string> > aiData, TreeNode tn, MasterTypes mType, int mNo, int iNo)
        {
            string strRoutineName = "AI";

            try
            {
                masterType = mType;
                masterNo   = mNo;
                IEDNo      = iNo;
                SetSupportedAttributes();
                SetSupportedResponseTypes();
                SetSupportedDataTypes();
                try
                {
                    ainType = (aiType)Enum.Parse(typeof(aiType), aiName);
                }
                catch (System.ArgumentException)
                {
                    Utils.WriteLine(VerboseLevel.WARNING, "Enum argument {0} not supported!!!", aiName);
                }
                //Parse n store values...
                if (aiData != null && aiData.Count > 0)
                {
                    foreach (KeyValuePair <string, string> aikp in aiData)
                    {
                        Utils.Write(VerboseLevel.DEBUG, "{0} {1} ", aikp.Key, aikp.Value);
                        try
                        {
                            if (this.GetType().GetProperty(aikp.Key) != null) //Ajay: 10/08/2018
                            {
                                this.GetType().GetProperty(aikp.Key).SetValue(this, aikp.Value);
                            }
                        }
                        catch (System.NullReferenceException)
                        {
                            Utils.WriteLine(VerboseLevel.WARNING, "Field doesn't exist. XML and class fields mismatch!!! key: {0} value: {1}", aikp.Key, aikp.Value);
                        }
                    }
                    Utils.Write(VerboseLevel.DEBUG, "\n");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(strRoutineName + ": " + "Error: " + ex.Message.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        public AI(string aiName, List <KeyValuePair <string, string> > aiData, TreeNode tn, MasterTypes mType, int mNo, int iNo)
        {
            string strRoutineName = "AI";

            try
            {
                masterType = mType;
                masterNo   = mNo;
                IEDNo      = iNo;
                SetSupportedAttributes();
                SetSupportedResponseTypes();
                SetSupportedDataTypes();
                try
                {
                    ainType = (aiType)Enum.Parse(typeof(aiType), aiName);
                }
                catch (System.ArgumentException)
                {
                }
                if (aiData != null && aiData.Count > 0) //Parse n store values...
                {
                    foreach (KeyValuePair <string, string> aikp in aiData)
                    {
                        try
                        {
                            if (this.GetType().GetProperty(aikp.Key) != null) //Ajay: 03/07/2018
                            {
                                this.GetType().GetProperty(aikp.Key).SetValue(this, aikp.Value);
                            }
                        }
                        catch (System.NullReferenceException)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(strRoutineName + ": " + "Error: " + ex.Message.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public AI(XmlNode aiNode, MasterTypes mType, int mNo, int iNo, bool imported)
        {
            string strRoutineName = "AI";

            try
            {
                masterType = mType;
                masterNo   = mNo;
                IEDNo      = iNo;
                SetSupportedAttributes();
                SetSupportedResponseTypes();
                SetSupportedDataTypes();
                Utils.WriteLine(VerboseLevel.DEBUG, "aiNode name: '{0}'", aiNode.Name);
                if (aiNode.Attributes != null)
                {
                    try
                    {
                        ainType = (aiType)Enum.Parse(typeof(aiType), aiNode.Name);
                    }
                    catch (System.ArgumentException)
                    {
                        Utils.WriteLine(VerboseLevel.WARNING, "Enum argument {0} not supported!!!", aiNode.Name);
                    }
                    if (masterType == MasterTypes.ADR || masterType == MasterTypes.IEC101 || masterType == MasterTypes.IEC103 || masterType == MasterTypes.MODBUS || masterType == MasterTypes.Virtual)
                    {
                        foreach (XmlAttribute item in aiNode.Attributes)
                        {
                            Utils.Write(VerboseLevel.DEBUG, "{0} {1} ", item.Name, item.Value);
                            try
                            {
                                if (this.GetType().GetProperty(item.Name) != null) //Ajay: 10/08/2018
                                {
                                    this.GetType().GetProperty(item.Name).SetValue(this, item.Value);
                                }
                            }
                            catch (System.NullReferenceException)
                            {
                                Utils.WriteLine(VerboseLevel.WARNING, "Field doesn't exist. XML and class fields mismatch!!! key: {0} value: {1}", item.Name, item.Value);
                            }
                        }
                    }
                    //Namrata: 17/7/2017
                    // If master Type is IEC61850Client
                    if (masterType == MasterTypes.IEC61850Client)
                    {
                        if (aiNode.Name == "AI")
                        {
                            foreach (XmlAttribute xmlattribute in aiNode.Attributes)
                            {
                                Utils.Write(VerboseLevel.DEBUG, "{0} {1} ", xmlattribute.Name, xmlattribute.Value);
                                try
                                {
                                    if (xmlattribute.Name == "ResponseType")
                                    {
                                        Iec61850ResponseType = aiNode.Attributes[1].Value;
                                    }
                                    else if (xmlattribute.Name == "Index")
                                    {
                                        Iec61850Index = aiNode.Attributes[2].Value;
                                    }
                                    else if (xmlattribute.Name == "FC")
                                    {
                                        fc = aiNode.Attributes[3].Value;
                                    }
                                    else
                                    {
                                        if (this.GetType().GetProperty(xmlattribute.Name) != null) //Ajay: 10/08/2018
                                        {
                                            this.GetType().GetProperty(xmlattribute.Name).SetValue(this, xmlattribute.Value);
                                        }
                                    }
                                }
                                catch (System.NullReferenceException)
                                {
                                    Utils.WriteLine(VerboseLevel.WARNING, "DI: Field doesn't exist. XML and class fields mismatch!!! key: {0} value: {1}", xmlattribute.Name, xmlattribute.Value);
                                }
                            }
                        }
                    }
                    Utils.Write(VerboseLevel.DEBUG, "\n");
                }
                else if (aiNode.NodeType == XmlNodeType.Comment)
                {
                    isNodeComment = true;
                    comment       = aiNode.Value;
                }
                if (imported)//Generate a new unique id...
                {
                    this.AINo = (Globals.AINo + 1).ToString();
                    if (masterType == MasterTypes.IEC103)
                    {
                        //Commented as asked by Amol, 29 / 12 / 2k16:
                        //this.Index = (Globals.AIIndex + 1).ToString();
                    }
                    else if (masterType == MasterTypes.ADR)
                    {
                        //Commented as asked by Amol, 29/12/2k16: this.Index = (Globals.AIIndex + 1).ToString();
                    }
                    else if (masterType == MasterTypes.MODBUS)
                    {
                        //Commented as asked by Amol, 29 / 12 / 2k16: this.Index = (Globals.AIIndex + 1).ToString();
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(strRoutineName + ": " + "Error: " + Ex.Message.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #4
0
        public AI(aiType aiType, aiAttackType aiAttackType, aiOrientation aiOrientation, AiWeapon aiWeapon, int costumeNum, AiAnimation aiAnim)
        {
            myAiType        = aiType;
            myAiAttackType  = aiAttackType;
            myAiOrientation = aiOrientation;
            costumeType     = costumeNum;
            myAiAnims       = aiAnim;
            myAiWeapon      = aiWeapon;
            mySpeed         = 5;

            //for (int i = 0; i < 10; i++)
            //{
            //    bullet[i] = new Bullet(bulletTexture, new Vector2(2000, 2000), 1);
            //    bullet[i].myCamera = myCamera;
            //    bullet[i].isEnemyBullet = true;
            //}

            //randomize speed
            //isDead = false;
            // change frame numbers

            //myAnimations[0] = new AnimatedSprite(myAiAnims.thugIdleSprites[costumeType], 1, 4, animSpeed);
            //myAnimations[1] = new AnimatedSprite(myAiAnims.civKnifeSprites[costumeType], 1, 3, animSpeed);
            //myAnimations[2] = new AnimatedSprite(myAiAnims.thugDieSprites[costumeType], 1, 3, animSpeed);

            switch (myAiType)
            {
            case aiType.standingThug:
                if (myAiOrientation == aiOrientation.Bad)
                {
                    if (myAiAttackType == aiAttackType.Melee)
                    {
                        myAnimations[0] = new AnimatedSprite(myAiAnims.thugIdleSprites[costumeType], 1, 4, animSpeed);
                        myAnimations[2] = new AnimatedSprite(myAiAnims.thugFloorSprites[costumeType], 1, 3, animSpeed);
                    }
                    else if (myAiAttackType == aiAttackType.Range)
                    {
                        myAnimations[0] = new AnimatedSprite(myAiAnims.thugIdleSprites[costumeType], 1, 4, animSpeed);
                        myAnimations[2] = new AnimatedSprite(myAiAnims.thugFloorSprites[costumeType], 1, 3, animSpeed);
                    }
                }
                else if (myAiOrientation == aiOrientation.Good)
                {
                    //  if (myAiAttackType == aiAttackType.Idle)
                    myAnimations[0] = new AnimatedSprite(myAiAnims.thugIdleSprites[costumeType], 1, 4, animSpeed);
                    myAnimations[2] = new AnimatedSprite(myAiAnims.thugFloorSprites[costumeType], 1, 3, animSpeed);
                }
                break;

            case aiType.standingCivilian:
                if (myAiOrientation == aiOrientation.Bad)
                {
                    if (myAiAttackType == aiAttackType.Melee)
                    {
                        myAnimations[0] = new AnimatedSprite(myAiAnims.civIdleSprites[costumeType], 1, 4, animSpeed);
                        myAnimations[2] = new AnimatedSprite(myAiAnims.civFloorSprites[costumeType], 1, 3, animSpeed);
                    }
                    else if (myAiAttackType == aiAttackType.Range)
                    {
                        myAnimations[0] = new AnimatedSprite(myAiAnims.civIdleSprites[costumeType], 1, 4, animSpeed);
                        myAnimations[2] = new AnimatedSprite(myAiAnims.civFloorSprites[costumeType], 1, 3, animSpeed);
                    }
                }
                else if (myAiOrientation == aiOrientation.Good)
                {
                    //    if (myAiAttackType == aiAttackType.Idle)
                    //    {
                    myAnimations[0] = new AnimatedSprite(myAiAnims.civIdleSprites[costumeType], 1, 4, animSpeed);
                    myAnimations[2] = new AnimatedSprite(myAiAnims.civFloorSprites[costumeType], 1, 3, animSpeed);
                    //     }
                }
                break;

            case aiType.walkingThug:
                if (myAiOrientation == aiOrientation.Bad)
                {
                    if (myAiAttackType == aiAttackType.Melee)
                    {
                        myAnimations[0] = new AnimatedSprite(myAiAnims.thugWalkSprites[costumeType], 1, 8, animSpeed);
                        myAnimations[2] = new AnimatedSprite(myAiAnims.thugFloorSprites[costumeType], 1, 3, animSpeed);
                    }
                    else if (myAiAttackType == aiAttackType.Range)
                    {
                        myAnimations[0] = new AnimatedSprite(myAiAnims.thugWalkSprites[costumeType], 1, 8, animSpeed);
                        myAnimations[2] = new AnimatedSprite(myAiAnims.thugFloorSprites[costumeType], 1, 3, animSpeed);
                    }
                }
                else if (myAiOrientation == aiOrientation.Good)
                {
                    //   if (myAiAttackType == aiAttackType.Idle)
                    //    {
                    myAnimations[0] = new AnimatedSprite(myAiAnims.thugWalkSprites[costumeType], 1, 8, animSpeed);
                    myAnimations[2] = new AnimatedSprite(myAiAnims.thugFloorSprites[costumeType], 1, 3, animSpeed);
                    //   }
                }
                break;

            case aiType.walkingCivilian:
                if (myAiOrientation == aiOrientation.Bad)
                {
                    if (myAiAttackType == aiAttackType.Melee)
                    {
                        myAnimations[0] = new AnimatedSprite(myAiAnims.civWalkSprites[costumeType], 1, 8, animSpeed);
                        myAnimations[2] = new AnimatedSprite(myAiAnims.civFloorSprites[costumeType], 1, 3, animSpeed);
                    }
                    else if (myAiAttackType == aiAttackType.Range)
                    {
                        myAnimations[0] = new AnimatedSprite(myAiAnims.civWalkSprites[costumeType], 1, 8, animSpeed);
                        myAnimations[2] = new AnimatedSprite(myAiAnims.civFloorSprites[costumeType], 1, 3, animSpeed);
                    }
                }
                else if (myAiOrientation == aiOrientation.Good)
                {
                    //   if (myAiAttackType == aiAttackType.Idle)
                    myAnimations[0] = new AnimatedSprite(myAiAnims.civWalkSprites[costumeType], 1, 8, animSpeed);
                    myAnimations[2] = new AnimatedSprite(myAiAnims.civFloorSprites[costumeType], 1, 3, animSpeed);
                }
                break;
            }

            assignWeapon();

            currentAnimation = myAnimations[0];
        }
Пример #5
0
        public AI(XmlNode aiNode, MasterTypes mType, int mNo, int iNo, bool imported)
        {
            string strRoutineName = "AI";

            try
            {
                masterType = mType;
                masterNo   = mNo;
                IEDNo      = iNo;
                SetSupportedAttributes();
                SetSupportedResponseTypes();
                SetSupportedDataTypes();
                if (aiNode.Attributes != null)
                {
                    try
                    {
                        ainType = (aiType)Enum.Parse(typeof(aiType), aiNode.Name);
                    }
                    catch (System.ArgumentException)
                    {
                    }
                    if (masterType == MasterTypes.ADR || masterType == MasterTypes.IEC101 || masterType == MasterTypes.IEC103 || masterType == MasterTypes.MODBUS || masterType == MasterTypes.Virtual || masterType == MasterTypes.IEC104 || masterType == MasterTypes.SPORT || masterType == MasterTypes.LoadProfile) //Ajay: 31/07/2018 LoadProfile Added
                    {
                        foreach (XmlAttribute item in aiNode.Attributes)
                        {
                            try
                            {
                                if (this.GetType().GetProperty(item.Name) != null) //Ajay: 03/07/2018
                                {
                                    this.GetType().GetProperty(item.Name).SetValue(this, item.Value);
                                }
                            }
                            catch (System.NullReferenceException)
                            {
                            }
                        }
                    }
                    // If master Type is IEC61850Client
                    if (masterType == MasterTypes.IEC61850Client) //Namrata: 17/7/2017
                    {
                        if (aiNode.Name == "AI")
                        {
                            foreach (XmlAttribute xmlattribute in aiNode.Attributes)
                            {
                                try
                                {
                                    if (xmlattribute.Name == "ResponseType")
                                    {
                                        Iec61850ResponseType = aiNode.Attributes[1].Value;
                                    }
                                    else if (xmlattribute.Name == "Index")
                                    {
                                        Iec61850Index = aiNode.Attributes[2].Value;
                                    }
                                    else if (xmlattribute.Name == "FC")
                                    {
                                        fc = aiNode.Attributes[3].Value;
                                    }
                                    else
                                    {
                                        if (this.GetType().GetProperty(xmlattribute.Name) != null) //Ajay: 03/07/2018
                                        {
                                            this.GetType().GetProperty(xmlattribute.Name).SetValue(this, xmlattribute.Value);
                                        }
                                    }
                                }
                                catch (System.NullReferenceException)
                                {
                                }
                            }
                        }
                    }
                }
                else if (aiNode.NodeType == XmlNodeType.Comment)
                {
                    isNodeComment = true;
                    comment       = aiNode.Value;
                }
                if (imported)//Generate a new unique id...
                {
                    this.AINo = (Globals.AINo + 1).ToString();
                    if (masterType == MasterTypes.IEC103)
                    {
                    }
                    else if (masterType == MasterTypes.ADR)
                    {
                        //Commented as asked by Amol, 29/12/2k16: this.Index = (Globals.AIIndex + 1).ToString();
                    }
                    else if (masterType == MasterTypes.MODBUS)
                    {
                        //Commented as asked by Amol, 29 / 12 / 2k16: this.Index = (Globals.AIIndex + 1).ToString();
                    }
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(strRoutineName + ": " + "Error: " + Ex.Message.ToString(), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }