public void Start()
    {
        Debug.Log("dataWarehouse main:" + dataWarehouse.main);
        RoleRecord default1 = careerList.main.randomRoleFor(3, false);

        default1.location = new vec2i(1, 1);
        enermys.Add(default1);

        RoleRecord default2 = careerList.main.randomRoleFor(3, false);

        default2.location = new vec2i(2, 1);
        enermys.Add(default2);

        RoleRecord default3 = careerList.main.randomRoleFor(2, false);

        default3.location = new vec2i(0, 1);
        enermys.Add(default3);

        RoleRecord default4 = careerList.main.randomRoleFor(2, false);

        default4.location = new vec2i(3, 3);
        //enermys.Add(default4);

        RoleRecord reward_role1 = careerList.main.randomRoleFor(3, true);
        RoleRecord reward_role2 = careerList.main.randomRoleFor(2, true);

        dataWarehouse.main.levelReward.roles = new List <RoleRecord>()
        {
            reward_role1, reward_role2
        };
        dataWarehouse.main.levelReward.itemNos = new List <int>()
        {
            0, 1, 2
        };
    }
Beispiel #2
0
    public RoleRecord randomRoleFor(int level, bool teammate)
    {
        RoleRecord newRole = randomRoleFor(level);

        newRole.teammate = teammate;
        return(newRole);
    }
Beispiel #3
0
    public RoleRecord randomRoleFor(int level)
    {//level1為種族 level2為基礎職業
        if (level < 2)
        {
            Debug.LogWarning("randomRoleFor 的level為:" + level + "小於2");
            return(null);
        }
        RoleRecord newRole = new RoleRecord();
        int        race    = baseRaceNos[UnityEngine.Random.Range(0, baseRaceNos.Count)];

        level -= 2;
        giveRace(newRole, objects[race]);
        int       index     = UnityEngine.Random.Range(0, baseCareerNos.Count);
        int       no        = baseCareerNos[index];
        careerInf nowCareer = objects[no];

        transferTo(newRole, nowCareer);
        for (int nowlv = 0; nowlv < level; nowlv++)
        {
            int nextNo = nowCareer.nexrCareer[UnityEngine.Random.Range(0, nowCareer.nexrCareer.Count)];
            nowCareer = objects[nextNo];
            transferTo(newRole, nowCareer);
        }
        return(newRole);
    }
Beispiel #4
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            IController sender = actionInput.Controller;

            string[] normalizedParams = this.NormalizeParameters(sender);
            string   role             = normalizedParams[0];
            string   playerName       = normalizedParams[1];

            Thing player = GameAction.GetPlayerOrMobile(playerName);

            if (player == null)
            {
                // If the player is not online, then load the player from the database
                //player = PlayerBehavior.Load(playerName);
            }

            var userControlledBehavior = player.Behaviors.FindFirst <UserControlledBehavior>();
            var existingRole           = (from r in userControlledBehavior.Roles where r.Name == role select r).FirstOrDefault();

            if (existingRole == null)
            {
                var roleRepository = new RoleRepository();

                // @@@ TODO: The role.ToUpper is a hack. Need to create a case insensitive method for the RoleRepository.NoGen.cs class.
                RoleRecord record = roleRepository.GetByName(role.ToUpper());
                //userControlledBehavior.RoleRecords.Add(record);
                //userControlledBehavior.UpdateRoles();
                player.Save();

                sender.Write(player.Name + " has been granted the " + role + " role.", true);
            }
        }
Beispiel #5
0
 public void Remove(RoleRecord role)
 {
     using (IDbCommand session = Helpers.OpenSession())
         using (IDbTransaction transaction = session.Connection.BeginTransaction())
         {
             session.Connection.Delete(role);
             transaction.Commit();
         }
 }
    public void createHead(RoleRecord data)
    {
        GameObject headIcon = Instantiate(headPrafeb, panel.transform);

        headIcon.transform.localPosition                = new Vector2(x_start + x_offset * heads.Count, y_pos);
        headIcon.GetComponent <headEvent>().data        = data;
        headIcon.GetComponent <headEvent>().rolePanel   = rolePanel;
        headIcon.GetComponent <SpriteRenderer>().sprite = ImageList.main.headIcons[data.race];
        heads.Add(headIcon);
    }
Beispiel #7
0
        public IEnumerable <string> GetPermissionsForRole(int id)
        {
            var        permissions = new List <string>();
            RoleRecord roleRecord  = GetRole(id);

            foreach (RolesPermissionsRecord rolesPermission in roleRecord.RolesPermissions)
            {
                permissions.Add(rolesPermission.Permission.Name);
            }
            return(permissions);
        }
Beispiel #8
0
    public static void transferTo(RoleRecord role, careerInf traget)
    {
        role.careers.Add(traget.careerNo);
        List <int> skills = new List <int>(); //所有技能池內角色尚未擁有的技能

        foreach (int no in traget.giftSkills) //添加所有必定獲得的技能
        {
            string name = SkillList.main.representation[no];
            if (Type.GetType("subst_skill_representation").IsAssignableFrom(Type.GetType(name)))
            //if (Type.GetType(name).IsSubclassOf(Type.GetType("subst_skill_representation")))
            {//如果技能敘述繼承了subst_skill_representation
                //則改為從subst_skill_representation的替補中選擇一個技能名稱
                object repre = System.Activator.CreateInstance(System.Type.GetType(name));
                role.skillNos.Add(((subst_skill_representation)repre).substitutNo());
            }
            else
            {
                role.skillNos.Add(no);
            }
        }

        foreach (int no in traget.skillPool)
        {
            if (!role.skillNos.Contains(no))
            {
                skills.Add(no);
            }
        }
        if (skills.Count > 0)
        {
            int    index = UnityEngine.Random.Range(0, skills.Count);
            string name  = SkillList.main.representation[skills[index]];
            //Debug.Log("skill representation name:" + name + " issubclass:" + Type.GetType(name).IsSubclassOf(Type.GetType("subst_skill_representation")));
            if (Type.GetType("subst_skill_representation").IsAssignableFrom(Type.GetType(name)))
            //if (Type.GetType(name).IsSubclassOf(Type.GetType("subst_skill_representation")))
            {//如果技能敘述繼承了subst_skill_representation
                //則改為從subst_skill_representation的替補中選擇一個技能名稱
                object repre = System.Activator.CreateInstance(System.Type.GetType(name));
                role.skillNos.Add(((subst_skill_representation)repre).substitutNo());
            }
            else
            {
                role.skillNos.Add(skills[index]);
            }
            //role.skillNos.Add(skills[index]);
        }
        else
        {
            Debug.LogWarning("在轉職成" + traget.name + "的過程中並沒有新增任何人技能");
        }
        role.data.attributeUpdate = traget.Attributes;
    }
    // Use this for initialization
    void Start()
    {
        PlayerInf pinf = new PlayerInf();

        pinf.lv        = 10;
        pinf.moneyLeft = 66;
        pinf.itemInBag = new List <int>()
        {
            0, 2, 3, 4, 19
        };
        unitData unit1 = new unitData();

        unit1.Now_Attack       = 20;
        unit1.Now_Attack_Speed = 90;
        unit1.Now_Max_Life     = 199;
        RoleRecord role1 = new RoleRecord(2);

        role1.data = unit1;
        Debug.Log("role1.data: NowAtk:" + unit1.Now_Attack);
        unitData_Profile ud_pf = unit1.getProflie();

        Debug.Log("unitData: baseAttack:" + ud_pf.base_attack + " atkSpeed:" + ud_pf.attack_speed_reinforce + " maxLife:" + ud_pf.max_life_point);
        role1.itemNos = new List <int>()
        {
            1, 1, 2, 3
        };


        unitData unit2 = new unitData();

        unit2.Now_Mag_Reinforce  = 50;
        unit2.Now_Mag_Resistance = 97;
        unit2.Now_Armor          = 35;
        RoleRecord role2 = new RoleRecord(0);

        role2.data     = unit2;
        role2.skillNos = new List <int>()
        {
            1, 2, 26, 10
        };
        role2.location = new vec2i(1, 1);

        pinf.army.Add(role1);
        pinf.army.Add(role2);
        pinf.saveInf();

        PlayerInf newInf = PlayerInf.loadInf();

        newInf.printInf();
    }
Beispiel #10
0
    public List <int> baseCareerNos; //記錄基礎職業的信息編號
    public static void giveRace(RoleRecord role, careerInf traget)
    {
        role.race = traget.careerNo;
        if (role.skillNos.Count != 0)
        {
            Debug.LogWarning("添加種族" + traget.name + "的時候技能欄不為空");
        }
        foreach (int no in traget.giftSkills)
        {
            role.skillNos.Add(no);
        }

        role.data.attributeUpdate = traget.Attributes;
    }
Beispiel #11
0
    public void initRoleForCareer(RoleRecord role)
    {
        careerInf race = objects[role.race];

        if (role.skillNos.Count != 0)
        {
            Debug.LogWarning("在初始化角色種族" + race.name + "的時候技能欄不為空");
        }
        foreach (int no in race.skillPool)
        {
            role.skillNos.Add(no);
        }

        role.data.attributeUpdate = race.Attributes;

        foreach (int cno in role.careers)
        {
            careerInf  career = objects[cno];
            List <int> skills = new List <int>();//所有技能池內角色尚未擁有的技能
            foreach (int no in career.skillPool)
            {
                if (!role.skillNos.Contains(no))
                {
                    skills.Add(no);
                }
            }
            if (skills.Count > 0)
            {
                int    index = UnityEngine.Random.Range(0, skills.Count);
                string name  = SkillList.main.representation[skills[index]];
                if (Type.GetType("subst_skill_representation").IsAssignableFrom(Type.GetType(name)))
                //if (Type.GetType(name).IsSubclassOf(Type.GetType("subst_skill_representation")))
                {//如果技能敘述繼承了subst_skill_representation
                    //則改為從subst_skill_representation的替補中選擇一個技能名稱
                    object repre = System.Activator.CreateInstance(System.Type.GetType(name));
                    role.skillNos.Add(((subst_skill_representation)repre).substitutNo());
                }
                else
                {
                    role.skillNos.Add(skills[index]);
                }
            }
            else
            {
                Debug.LogWarning("在初始化職業時" + career.name + "的過程中並沒有新增任何人技能");
            }
            role.data.attributeUpdate = career.Attributes;
        }
    }
Beispiel #12
0
        public void CreateAllowedRoleForRole(string allowedRoleName, string roleName)
        {
            if (_roleService.GetRoleByName(allowedRoleName) == null)
            {
                return;
            }
            CreateAllowedRole(allowedRoleName);
            RoleRecord        roleRecord        = _roleService.GetRoleByName(roleName);
            AllowedRoleRecord allowedRoleRecord = _allowedRolesRepository.Get(x => x.AllowedRole == allowedRoleName);

            roleRecord.AllowedRoles.Add(new RoleAllowedRolesRecord {
                AllowedRole = allowedRoleRecord, Role = roleRecord
            });
            TriggerSignal();
        }
Beispiel #13
0
        public void CreateRole(string roleName)
        {
            if (GetRoleByName(roleName) != null)
            {
                return;
            }

            var roleRecord = new RoleRecord {
                Name = roleName
            };

            _roleRepository.Create(roleRecord);
            _roleEventHandlers.Created(new RoleCreatedContext {
                Role = roleRecord
            });
            TriggerSignal();
        }
Beispiel #14
0
    public void prepareRole(RoleRecord traget)
    {
        role = traget;
        cancer();
        Debug.Log("careers count:" + traget.careers.Count);
        int no = traget.careers[traget.careers.Count - 1];

        roleBox.sprite = ImageList.main.headIcons[traget.race];
        careerInf nowcareer = careerList.main.objects[no];

        foreach (int cno in nowcareer.nexrCareer)
        {
            careerInf  nextcareer = careerList.main.objects[cno];
            GameObject obj        = Instantiate(careerObj, upPanel.transform);
            obj.GetComponent <roleForUpgrade>().init(role, nextcareer, onPickCareer, aftUpgrade);
            objList.Add(obj);
        }
    }
        public void CreatePermissionForRole(string roleName, string permissionName)
        {
            if (_permissionRepository.Get(x => x.Name == permissionName) == null)
            {
                _permissionRepository.Create(new PermissionRecord {
                    Description = GetPermissionDescription(permissionName),
                    Name        = permissionName,
                    FeatureName = GetFeatureName(permissionName)
                });
            }
            RoleRecord       roleRecord       = GetRoleByName(roleName);
            PermissionRecord permissionRecord = _permissionRepository.Get(x => x.Name == permissionName);

            roleRecord.RolesPermissions.Add(new RolesPermissionsRecord {
                Permission = permissionRecord, Role = roleRecord
            });
            TriggerSignal();
        }
 public rolePanel panel;  //初始化時賦予
 public void init(RoleRecord inf, careerInf career, withCareer callback, withNone upgrade_callback)
 {
     roleInf     = inf;
     this.career = career;
     Debug.Log("Icon" + Icon + "race:" + inf.race);
     Icon.sprite = ImageList.main.headIcons[inf.race];
     if (itemName != null)
     {
         string name = career.name;
         itemName.text = name;
     }
     if (itemCost != null)
     {
         itemCost.text = "" + career.Price;
     }
     onClick_callback        = callback;
     onUpgradeFinsh_callback = upgrade_callback;
 }
Beispiel #17
0
 public void init(RoleRecord role)
 {
     nowRole         = role;
     headIcon.sprite = ImageList.main.headIcons[role.race];
     updateAttr(attribute.atk, "" + role.data.Now_Attack);
     updateAttr(attribute.max_hp, "" + role.data.Now_Max_Life);
     updateAttr(attribute.atk_accelerate, "" + role.data.Now_Attack_Speed);
     updateAttr(attribute.atk_interval, "" + role.data.Now_Attack_Interval);
     updateAttr(attribute.magic, "" + role.data.Now_Mag_Reinforce);
     updateAttr(attribute.mg_damage_reinforce, "" + role.data.Now_Mag_Multiple);
     updateAttr(attribute.cd_reinforce, "" + role.data.Now_Cooldown_Reinforce);
     updateAttr(attribute.cd_time_reduce, "" + role.data.Now_Cooldown_Mutiple);
     updateAttr(attribute.armor, "" + role.data.Now_Armor);
     updateAttr(attribute.phy_damage_reduce, "" + role.data.Physical_Reduce_Multiple);
     updateAttr(attribute.resistance, "" + role.data.Now_Mag_Resistance);
     updateAttr(attribute.mg_damage_reduce, "" + role.data.Magic_Reduce_Multiple);
     skillBar.init(role);
     equipBar.init(role);
 }
Beispiel #18
0
 public void init(RoleRecord data)
 {
     foreach (GameObject head in heads)
     {
         Destroy(head);
     }
     role = data;
     foreach (int no in role.skillNos)
     {
         //記得做createheadIcon
         GameObject pobj = Instantiate(IconPrab, transform);
         heads.Add(pobj);
         print("no:" + no);
         pobj.GetComponent <Image>().sprite = ImageList.main.skillIcons[no];
         print("技能" + IconPrab.name + "添加skillPanel" + skillPanel);
         pobj.GetComponent <showSkillInf>().panel = skillPanel;
         pobj.GetComponent <showSkillInf>().initInf(SkillList.main.representation[no], role.data);
         print("showSkillInf:" + IconPrab.GetComponent <showSkillInf>().panel);
     }
 }
Beispiel #19
0
    public void init(RoleRecord inf, GameObject panel)
    {
        roleInf     = inf;
        Icon.sprite = ImageList.main.headIcons[inf.race];
        if (itemName != null)
        {
            string name = careerList.main.objects[inf.careers[inf.careers.Count - 1]].name;
            itemName.text = name;
        }
        if (itemCost != null)
        {
            int price = 0;
            foreach (int careerno in roleInf.careers)
            {
                price += careerList.main.objects[careerno].Price;
            }
            itemCost.text = "" + price;
        }

        this.panel = panel.GetComponent <rolePanel>();
    }
Beispiel #20
0
    public void init(RoleRecord data)
    {
        foreach (GameObject head in heads)
        {
            Destroy(head);
        }
        role = data;
        int count = 0;

        foreach (int no in role.itemNos)
        {
            //記得做createheadIcon
            GameObject pobj = Instantiate(IconPrab, transform);
            heads.Add(pobj);
            print("no:" + no);
            pobj.GetComponent <Image>().sprite = ImageList.main.itemIcon[no];
            print("技能" + IconPrab.name + "添加skillPanel" + itemPanel);
            pobj.GetComponent <showItemInf>().panel = itemPanel;
            pobj.GetComponent <showItemInf>().initInf(no, itemList.main.representation[no], role.data, role.index, count);
            count++;
            //print("showSkillInf:" + IconPrab.GetComponent<showSkillInf>().panel);
        }
    }
        public void UpdateRole(int id, string roleName, IEnumerable <string> rolePermissions)
        {
            RoleRecord roleRecord = GetRole(id);

            roleRecord.Name = roleName;
            roleRecord.RolesPermissions.Clear();
            foreach (var rolePermission in rolePermissions)
            {
                string permission = rolePermission;
                if (_permissionRepository.Get(x => x.Name == permission) == null)
                {
                    _permissionRepository.Create(new PermissionRecord {
                        Description = GetPermissionDescription(permission),
                        Name        = permission,
                        FeatureName = GetFeatureName(permission)
                    });
                }
                PermissionRecord permissionRecord = _permissionRepository.Get(x => x.Name == permission);
                roleRecord.RolesPermissions.Add(new RolesPermissionsRecord {
                    Permission = permissionRecord, Role = roleRecord
                });
            }
            TriggerSignal();
        }
    public void createHead(int groupNo, RoleRecord data)
    {
        GameObject[,] map = girdControl.girdGroups[groupNo];
        vec2i   location;
        Vector2 pos = new Vector2(0, 0);

        if (groupNo % 2 == 1)
        {
            location = data.location;
            pos      = map[location.y, location.x].transform.position;
        }
        else if (groupNo % 2 == 0)
        {
            location = data.location;
            pos      = map[3 - data.location.y, location.x].transform.position;
        }
        GameObject headIcon = Instantiate(headPrafeb, pos, Quaternion.Euler(0, 0, 0));

        headIcon.GetComponent <headEvent>().data      = data;
        headIcon.GetComponent <headEvent>().rolePanel = rolePanel;
        heads.Add(headIcon);
        headIcon.GetComponent <SpriteRenderer>().sprite          = ImageList.main.headIcons[data.race];
        headIcon.GetComponent <SpriteRenderer>().maskInteraction = SpriteMaskInteraction.None;
    }
Beispiel #23
0
 public void none(RoleRecord arg)
 {
 }
Beispiel #24
0
 void setData(RoleRecord d)
 {
     data = d;
 }
        private void PrintRoleRecord(RoleRecord roleRecord, int initialIndent = 0)
        {
            var secondIndent = initialIndent + 2;

            Context.Output.Write(new string(' ', initialIndent));
            Context.Output.WriteLine(T("{0}", roleRecord.Name));

            if (IncludePermissions)
            {
                Context.Output.Write(new string(' ', secondIndent));
                Context.Output.WriteLine(T("List of Permissions"));

                Context.Output.Write(new string(' ', secondIndent));
                Context.Output.WriteLine(T("--------------------------"));

                var permissionsEnumerable =
                    roleRecord.RolesPermissions
                    .Where(record => WithFeature == null || record.Permission.FeatureName == WithFeature)
                    .Where(record => WithPermission == null || record.Permission.Name == WithPermission);

                var orderedPermissionsEnumerable =
                    permissionsEnumerable
                    .OrderBy(record => record.Permission.FeatureName)
                    .ThenBy(record => record.Permission.Name);

                foreach (var rolesPermissionsRecord in orderedPermissionsEnumerable)
                {
                    Context.Output.Write(new string(' ', secondIndent));
                    Context.Output.Write("Feature Name:".PadRight(15));
                    Context.Output.WriteLine(rolesPermissionsRecord.Permission.FeatureName);

                    Context.Output.Write(new string(' ', secondIndent));
                    Context.Output.Write("Permission:".PadRight(15));
                    Context.Output.WriteLine(rolesPermissionsRecord.Permission.Name);

                    Context.Output.Write(new string(' ', secondIndent));
                    Context.Output.Write("Description:".PadRight(15));
                    Context.Output.WriteLine(rolesPermissionsRecord.Permission.Description);
                    Context.Output.WriteLine();
                }
            }

            if (IncludeUsers)
            {
                var userRolesPartRecords = _userRolesRepository.Fetch(record => record.Role.Name == roleRecord.Name);

                Context.Output.Write(new string(' ', secondIndent));
                Context.Output.WriteLine(T("List of Users"));

                Context.Output.Write(new string(' ', secondIndent));
                Context.Output.WriteLine(T("--------------------------"));

                foreach (var userRolesPartRecord in userRolesPartRecords)
                {
                    var userRolesPart = _contentManager.Get <UserRolesPart>(userRolesPartRecord.UserId);
                    var user          = userRolesPart.As <IUser>();

                    Context.Output.Write(new string(' ', secondIndent));
                    Context.Output.Write("UserName:"******"Email:".PadRight(15));
                    Context.Output.WriteLine(user.Email);
                    Context.Output.WriteLine();
                }
            }
        }
Beispiel #26
0
 public void removeRole(RoleRecord role)
 {
     roles.Remove(role);
 }
Beispiel #27
0
 public void onPick(RoleRecord role)
 {
     master.prepareRole(role);
 }
    public override void onEnvReady(Manager manager)
    {
        int index = Randomer.main.getInt();

        //index = index % creatureList.main.names.Count;
        index = 3;
        RoleRecord   data = creatureList.main.getObjectIn(index);
        BasicManager bm   = (BasicManager)manager;

        int[] pos = ((ChessBoard)owner.env).getPosFor(owner);
        Dictionary <string, object> unitDic = null;
        ChessBoard   cb        = ((ChessBoard)owner.env);
        List <int[]> emptyList = new List <int[]>();

        if (owner.playerNo % 2 == 0)
        {
            if (pos[1] < 3)
            {
                if (cb.board[pos[1] + 1, pos[0]] == null)
                {
                    int[] tragetpos = new int[] { pos[0], pos[1] + 1 };
                    pos     = toRelativePos(tragetpos, owner.playerNo, cb);
                    unitDic = new Dictionary <string, object>()
                    {
                        { BasicManager.STR_POS_Y, pos[1] }, { BasicManager.STR_POS_X, pos[0] }, { BasicManager.STR_PLAYER_NO, owner.playerNo }, { BasicManager.STR_INF, data }
                    };
                }
            }
            if (unitDic == null)
            {
                for (int x = 0; x < cb.X; x++)
                {
                    for (int y = 0; y < cb.Y / 2; y++)
                    {
                        if (cb.board[y, x] == null)
                        {
                            emptyList.Add(new int[2] {
                                x, y
                            });
                        }
                    }
                }
            }
        }
        else
        {
            if (pos[1] > 4)
            {
                if (cb.board[pos[1] - 1, pos[0]] == null)
                {
                    int[] tragetpos = new int[] { pos[0], pos[1] - 1 };
                    pos     = toRelativePos(tragetpos, owner.playerNo, cb);
                    unitDic = new Dictionary <string, object>()
                    {
                        { BasicManager.STR_POS_Y, pos[1] }, { BasicManager.STR_POS_X, pos[0] }, { BasicManager.STR_PLAYER_NO, owner.playerNo }, { BasicManager.STR_INF, data }
                    };
                }
            }
            if (unitDic == null)
            {
                for (int x = 0; x < cb.X; x++)
                {
                    for (int y = cb.Y / 2; y < cb.Y; y++)
                    {
                        if (cb.board[y, x] == null)
                        {
                            emptyList.Add(new int[2] {
                                x, y
                            });
                        }
                    }
                }
            }
        }
        if (unitDic == null)
        {
            int posidx = Randomer.main.getInt() % emptyList.Count;
            pos     = emptyList[posidx];
            pos     = toRelativePos(pos, owner.playerNo, cb);
            unitDic = new Dictionary <string, object>()
            {
                { BasicManager.STR_POS_Y, pos[1] }, { BasicManager.STR_POS_X, pos[0] }, { BasicManager.STR_PLAYER_NO, owner.playerNo }, { BasicManager.STR_INF, data }
            };
        }
        Debug.Log("創建單位x:" + unitDic[BasicManager.STR_POS_X] + ",y:" + unitDic[BasicManager.STR_POS_Y]);
        bm.createUnit(unitDic);
    }
Beispiel #29
0
 public void init(RoleRecord data)
 {
     this.data = data;
     GetComponent <SpriteRenderer>().sprite = ImageList.main.headIcons[data.race];
 }
Beispiel #30
0
    public unitControler createUnit(Dictionary <string, object> unitInf)
    {
        Debug.Log("創建新的單位");
        int posX = (int)unitInf["position_x"];
        int posY = (int)unitInf["position_y"];

        RoleRecord inf      = ((RoleRecord)unitInf["information"]);
        int        unitNo   = inf.race;
        int        playerNo = (int)unitInf["player_no"];
        List <int> skillnos = inf.skillNos;
        List <int> itemnos  = inf.itemNos;
        unitData   data     = inf.data;
        int        realX    = 0;
        int        realY    = 0;
        GameObject newone   = Instantiate(objectList.main.mainUnit);

        newone.name = "隨機" + UnityEngine.Random.Range(0, 100);
        Debug.Log("playerNo:" + playerNo + " chessx:" + chessBoard.X + " chessy:" + chessBoard.Y);
        //Debug.Log("realY")
        if (playerNo % 2 == 0)
        {
            realX = posX;
            realY = chessBoard.Y / 2 - 1 - posY;
        }
        else if (playerNo % 2 == 1)
        {
            realX = posX;
            realY = chessBoard.Y / 2 + posY;
        }
        newone.transform.position = new Vector2(INIT_X + realX * X_INTERVAL, INIT_Y + realY * Y_INTERVAL);
        BasicControler controler = newone.AddComponent <BasicControler>();

        controler.playerNo = playerNo;
        newone.GetComponent <SpriteRenderer>().sprite = ImageList.main.headIcons[unitNo];
        bool result = chessBoard.enter(controler, realX, realY);

        Debug.Log("result:" + result);
        if (result)
        {
            GameObject hpbar = Instantiate(objectList.main.hpBar, newone.transform);
            hpbar.transform.localPosition        = objectList.main.hpBar.transform.position;
            hpbar.GetComponent <HpBar>().HpColor = playerColor[playerNo];
            //要複製一個新的unitData,不然在戰鬥中的技能可能會永久地改變角色屬性
            controler.init(new BasicAI(), chessBoard, new unitData(data), hpbar.GetComponent <HpBar>());
            controler._onDeath = forRoleDeath;
            Timer.main.logInTimer(controler.action);
            newone.AddComponent <sp_effection>();
            SkillBelt belt = newone.AddComponent <SkillBelt>();
            controler.skillBelt = belt;
            belt.init(controler, skillnos);
            itemBelt item_belt = newone.AddComponent <itemBelt>();
            item_belt.init(controler, itemnos);
            //是否要用字串來儲存技能名?
            return(controler);
        }
        else
        {
            Destroy(newone);
            return(null);
        }
    }