Commit f1192a584a0201800b9dd4fca5d1ad9292799491
1 parent
3e2ecbe7
Exists in
master
队伍buff相关
Showing
4 changed files
with
298 additions
and
1 deletions
Show diff stats
src/HttpServer/logic/datadef.go
| ... | ... | @@ -162,9 +162,29 @@ type TeamMemInfo struct { |
| 162 | 162 | MemList []int |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | +//玩家投资信心 | |
| 166 | +type TeamDevoteInfo struct { | |
| 167 | + UserId int `json:"userid"` | |
| 168 | + Type int `json:"type"` | |
| 169 | + Assets int `json:"assets"` | |
| 170 | +} | |
| 171 | + | |
| 172 | +//玩家buff | |
| 173 | +type TeamBuffInfo struct { | |
| 174 | + BeginTime int | |
| 175 | + EndTime int | |
| 176 | +} | |
| 177 | + | |
| 178 | +// | |
| 179 | +type TeamAllBuff struct { | |
| 180 | + Type int | |
| 181 | + BuffInfo []TeamBuffInfo | |
| 182 | +} | |
| 183 | + | |
| 165 | 184 | //队伍建筑信息 |
| 166 | 185 | type TeamBuildingInfo struct { |
| 167 | - | |
| 186 | + Devote []TeamDevoteInfo | |
| 187 | + Buff []TeamAllBuff | |
| 168 | 188 | } |
| 169 | 189 | |
| 170 | 190 | type CreateTeamInfo struct { |
| ... | ... | @@ -235,6 +255,59 @@ type QuitTeamResp struct { |
| 235 | 255 | Result CommonResult `json:"result"` |
| 236 | 256 | } |
| 237 | 257 | |
| 258 | +type UpdateTeamBuildReq struct{ | |
| 259 | + Token string `json:"token"` | |
| 260 | + Build_type int `json:"build_type"` | |
| 261 | + Assets int `json:"assets"` | |
| 262 | + Muti int `json:"muti"` | |
| 263 | +} | |
| 264 | + | |
| 265 | +type QuitTeamDesc struct { | |
| 266 | + Build_list []TeamDevoteInfo `json:"build_list"` | |
| 267 | +} | |
| 268 | + | |
| 269 | +type QuitTeamResult struct { | |
| 270 | + Code int `json:"code"` | |
| 271 | + Data QuitTeamDesc `json:"data"` | |
| 272 | +} | |
| 273 | + | |
| 274 | +type UpdateTeamBuildResp struct { | |
| 275 | + Status string `json:"status"` | |
| 276 | + Result QuitTeamResult `json:"result"` | |
| 277 | +} | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | +type AddTeamBuffReq struct{ | |
| 282 | + Token string `json:"token"` | |
| 283 | + Build_type int `json:"build_type"` | |
| 284 | + Muti int `json:"muti"` | |
| 285 | +} | |
| 286 | + | |
| 287 | +type BuffTimeInfo struct { | |
| 288 | + Buff_begin_time int `json:"buff_begin_time"` | |
| 289 | + Buff_end_time int `json:"buff_end_time"` | |
| 290 | +} | |
| 291 | + | |
| 292 | +type AddTeamBuffSpec struct { | |
| 293 | + Build_type int `json:"build_type"` | |
| 294 | + Buff_time []BuffTimeInfo `json:"buff_time"` | |
| 295 | +} | |
| 296 | + | |
| 297 | +type AddTeamBuffDesc struct { | |
| 298 | + Build_list []AddTeamBuffSpec `json:"build_list"` | |
| 299 | +} | |
| 300 | + | |
| 301 | +type AddTeamBuffResult struct { | |
| 302 | + Code int `json:"code"` | |
| 303 | + Data AddTeamBuffDesc `json:"data"` | |
| 304 | +} | |
| 305 | + | |
| 306 | +type AddTeamBuffResp struct { | |
| 307 | + Status string `json:"status"` | |
| 308 | + Result AddTeamBuffResult `json:"result"` | |
| 309 | +} | |
| 310 | + | |
| 238 | 311 | |
| 239 | 312 | //********************************************************************************************************** |
| 240 | 313 | ... | ... |
src/HttpServer/logic/function.go
| ... | ... | @@ -7,6 +7,7 @@ import ( |
| 7 | 7 | "encoding/json" |
| 8 | 8 | "net/http" |
| 9 | 9 | "strconv" |
| 10 | + "time" | |
| 10 | 11 | ) |
| 11 | 12 | |
| 12 | 13 | func SetHeader(w http.ResponseWriter) { |
| ... | ... | @@ -15,6 +16,82 @@ func SetHeader(w http.ResponseWriter) { |
| 15 | 16 | w.Header().Set("Access-Control-Allow-Headers", "Content-Type,Uuid") |
| 16 | 17 | } |
| 17 | 18 | |
| 19 | +func (tinfo *TeamInfo) DoAddBuffTimee(btype int,muti int,resp *AddTeamBuffResp) { | |
| 20 | + addtime := 1800*muti | |
| 21 | + index := 0 | |
| 22 | + for k,val := range tinfo.BInfo.Buff { | |
| 23 | + if val.Type == btype { | |
| 24 | + index = k | |
| 25 | + } | |
| 26 | + } | |
| 27 | + | |
| 28 | + for i:=0;i<len(tinfo.BInfo.Buff[index].BuffInfo);i++ { | |
| 29 | + tinfo.BInfo.Buff[index].BuffInfo[i].EndTime += addtime | |
| 30 | + } | |
| 31 | + | |
| 32 | + for _,vak := range tinfo.BInfo.Buff { | |
| 33 | + var tmp AddTeamBuffSpec | |
| 34 | + tmp.Build_type = vak.Type | |
| 35 | + for _,val1 := range vak.BuffInfo { | |
| 36 | + var tmp1 BuffTimeInfo | |
| 37 | + tmp1.Buff_begin_time = val1.BeginTime | |
| 38 | + tmp1.Buff_end_time = val1.EndTime | |
| 39 | + tmp.Buff_time = append(tmp.Buff_time,tmp1) | |
| 40 | + } | |
| 41 | + resp.Result.Data.Build_list = append(resp.Result.Data.Build_list,tmp) | |
| 42 | + } | |
| 43 | +} | |
| 44 | + | |
| 45 | +func (tinfo *TeamInfo) DoDevote(btype int,assets int ,uuid int,muti int) { | |
| 46 | + bfind := false | |
| 47 | + for k,val := range tinfo.BInfo.Devote { | |
| 48 | + if val.Type == btype { | |
| 49 | + tinfo.BInfo.Devote[k].Assets += assets | |
| 50 | + bfind = true | |
| 51 | + break | |
| 52 | + } | |
| 53 | + } | |
| 54 | + if !bfind { | |
| 55 | + var tmp TeamDevoteInfo | |
| 56 | + tmp.UserId = uuid | |
| 57 | + tmp.Assets = assets | |
| 58 | + tmp.Type = btype | |
| 59 | + tinfo.BInfo.Devote = append(tinfo.BInfo.Devote,tmp) | |
| 60 | + } | |
| 61 | + | |
| 62 | + //需要处理一下buff | |
| 63 | + nowtime := int(time.Now().Unix()) | |
| 64 | + addTime := 1800*muti | |
| 65 | + var index = 0 | |
| 66 | + for k,val := range tinfo.BInfo.Buff { | |
| 67 | + if val.Type == btype { | |
| 68 | + index = k | |
| 69 | + } | |
| 70 | + } | |
| 71 | + if tinfo.BInfo.Buff[index].BuffInfo[len(tinfo.BInfo.Buff[index].BuffInfo)-1].EndTime < nowtime + 86399 { | |
| 72 | + if tinfo.BInfo.Buff[index].BuffInfo[len(tinfo.BInfo.Buff[index].BuffInfo)-1].EndTime >= nowtime { | |
| 73 | + tinfo.BInfo.Buff[index].BuffInfo[len(tinfo.BInfo.Buff[index].BuffInfo)-1].EndTime += addTime | |
| 74 | + } else { | |
| 75 | + var tmp TeamBuffInfo | |
| 76 | + tmp.BeginTime = nowtime | |
| 77 | + tmp.EndTime = nowtime + addTime | |
| 78 | + tinfo.BInfo.Buff[index].BuffInfo = append(tinfo.BInfo.Buff[index].BuffInfo,tmp) | |
| 79 | + } | |
| 80 | + }else { | |
| 81 | + tinfo.BInfo.Buff[index].BuffInfo[len(tinfo.BInfo.Buff[index].BuffInfo)-1].EndTime += 86399 | |
| 82 | + } | |
| 83 | + | |
| 84 | + //删除掉无用的 | |
| 85 | + yestime := nowtime-86400 | |
| 86 | + for i:=0;i<len(tinfo.BInfo.Buff[index].BuffInfo);i++ { | |
| 87 | + v := tinfo.BInfo.Buff[index].BuffInfo[i] | |
| 88 | + if v.BeginTime < yestime && v.EndTime < yestime { | |
| 89 | + tinfo.BInfo.Buff = append(tinfo.BInfo.Buff[:i],tinfo.BInfo.Buff[i+1:]...) | |
| 90 | + i-- | |
| 91 | + } | |
| 92 | + } | |
| 93 | +} | |
| 94 | + | |
| 18 | 95 | func (tinfo *TeamInfo) IsInTeam(uuid int) bool { |
| 19 | 96 | inteam := false |
| 20 | 97 | for _,val := range tinfo.MemInfo.MemList { | ... | ... |
src/HttpServer/logic/httpserver.go
| ... | ... | @@ -39,12 +39,37 @@ func startServerHttpServe() { |
| 39 | 39 | http.HandleFunc("/catcafe/team/joinTeam", JoinTeam) //主动加入队伍 |
| 40 | 40 | http.HandleFunc("/catcafe/team/joinTeamByInvite", JoinTeamByInvite) //被邀请加入队伍 |
| 41 | 41 | http.HandleFunc("/catcafe/team/quitTeam", QuitTeam) //被邀请加入队伍 |
| 42 | + http.HandleFunc("/catcafe/team/updateTeamBuild", UpdateTeamBuild) //升级队伍建筑等级 | |
| 43 | + http.HandleFunc("/catcafe/team/addTeamBuff", AddTeamBuff) //添加BUFF时间 | |
| 42 | 44 | |
| 43 | 45 | |
| 44 | 46 | err := http.ListenAndServe(conf.GetServerHttpAddrConf(), nil) |
| 45 | 47 | CheckErr(err) |
| 46 | 48 | } |
| 47 | 49 | |
| 50 | + | |
| 51 | +func AddTeamBuff(w http.ResponseWriter, r *http.Request) { | |
| 52 | + | |
| 53 | + result, _ := ioutil.ReadAll(r.Body) | |
| 54 | + r.Body.Close() | |
| 55 | + | |
| 56 | + s := string(result) | |
| 57 | + logger.Info("AddTeamBuff , body:%v,uuid=%v", s) | |
| 58 | + | |
| 59 | + HandleAddTeamBuff(w,s) | |
| 60 | +} | |
| 61 | + | |
| 62 | +func UpdateTeamBuild(w http.ResponseWriter, r *http.Request) { | |
| 63 | + | |
| 64 | + result, _ := ioutil.ReadAll(r.Body) | |
| 65 | + r.Body.Close() | |
| 66 | + | |
| 67 | + s := string(result) | |
| 68 | + logger.Info("UpdateTeamBuild , body:%v,uuid=%v", s) | |
| 69 | + | |
| 70 | + HandleUpdateTeamBuild(w,s) | |
| 71 | +} | |
| 72 | + | |
| 48 | 73 | func QuitTeam(w http.ResponseWriter, r *http.Request) { |
| 49 | 74 | |
| 50 | 75 | result, _ := ioutil.ReadAll(r.Body) | ... | ... |
src/HttpServer/logic/logic.go
| ... | ... | @@ -763,4 +763,126 @@ func HandleQuitTeam(w http.ResponseWriter, data string) { |
| 763 | 763 | //回包 |
| 764 | 764 | respstr, _ := json.Marshal(&resp) |
| 765 | 765 | fmt.Fprint(w, string(respstr)) |
| 766 | +} | |
| 767 | + | |
| 768 | + | |
| 769 | +func HandleUpdateTeamBuild(w http.ResponseWriter, data string) { | |
| 770 | + SetHeader(w) | |
| 771 | + var resp UpdateTeamBuildResp | |
| 772 | + resp.Status = "true" | |
| 773 | + resp.Result.Code = ERROR_OK | |
| 774 | + var rdata UpdateTeamBuildReq | |
| 775 | + err := json.Unmarshal([]byte(data), &rdata) | |
| 776 | + for { | |
| 777 | + if err != nil { | |
| 778 | + logger.Error("HandleUpdateTeamBuild json unmarshal failed=%v", err) | |
| 779 | + resp.Result.Code = ERROR_JSONUNMASHFAILED | |
| 780 | + break | |
| 781 | + } | |
| 782 | + | |
| 783 | + uuid,err := GetTouristUid(rdata.Token) | |
| 784 | + if err != nil || uuid==0{ | |
| 785 | + logger.Error("HandleUpdateTeamBuild GetTouristUid failed=%v", err) | |
| 786 | + resp.Result.Code = ERROR_GETUSERIDFAILED | |
| 787 | + break | |
| 788 | + } | |
| 789 | + | |
| 790 | + teamid,err := GetTeamByUuid(uuid) | |
| 791 | + if err != nil { | |
| 792 | + logger.Error("HandleUpdateTeamBuild GetTeamInfoFailed failed=%v", err) | |
| 793 | + resp.Result.Code = ERROR_GETTEAMINFO_FAILED | |
| 794 | + break | |
| 795 | + } | |
| 796 | + tinfo ,err := GetTeamInfo(teamid) | |
| 797 | + if err != nil { | |
| 798 | + logger.Error("HandleUpdateTeamBuild GetTeamInfoFailed failed=%v", err) | |
| 799 | + resp.Result.Code = ERROR_GETTEAMINFO_FAILED | |
| 800 | + break | |
| 801 | + } | |
| 802 | + //判断一下是否已经在队伍中 | |
| 803 | + inteam := tinfo.IsInTeam(uuid) | |
| 804 | + | |
| 805 | + if !inteam { | |
| 806 | + logger.Error("HandleQuitTeam not inteam failed=%v", err) | |
| 807 | + resp.Result.Code = ERROR_TEAMNOTINTEAM | |
| 808 | + break | |
| 809 | + } | |
| 810 | + | |
| 811 | + | |
| 812 | + //处理投资 | |
| 813 | + tinfo.DoDevote(rdata.Build_type,rdata.Assets,uuid,rdata.Muti) | |
| 814 | + | |
| 815 | + //保存队伍数据 | |
| 816 | + SaveTeamInfo(tinfo.BaseInfo.Id,tinfo) | |
| 817 | + | |
| 818 | + for _,val := range tinfo.BInfo.Devote { | |
| 819 | + resp.Result.Data.Build_list = append(resp.Result.Data.Build_list,val) | |
| 820 | + } | |
| 821 | + | |
| 822 | + resp.Result.Code = ERROR_OK | |
| 823 | + break | |
| 824 | + } | |
| 825 | + | |
| 826 | + //回包 | |
| 827 | + respstr, _ := json.Marshal(&resp) | |
| 828 | + fmt.Fprint(w, string(respstr)) | |
| 829 | +} | |
| 830 | + | |
| 831 | +func HandleAddTeamBuff(w http.ResponseWriter, data string) { | |
| 832 | + SetHeader(w) | |
| 833 | + var resp AddTeamBuffResp | |
| 834 | + resp.Status = "true" | |
| 835 | + resp.Result.Code = ERROR_OK | |
| 836 | + var rdata AddTeamBuffReq | |
| 837 | + err := json.Unmarshal([]byte(data), &rdata) | |
| 838 | + for { | |
| 839 | + if err != nil { | |
| 840 | + logger.Error("HandleAddTeamBuff json unmarshal failed=%v", err) | |
| 841 | + resp.Result.Code = ERROR_JSONUNMASHFAILED | |
| 842 | + break | |
| 843 | + } | |
| 844 | + | |
| 845 | + uuid,err := GetTouristUid(rdata.Token) | |
| 846 | + if err != nil || uuid==0{ | |
| 847 | + logger.Error("HandleAddTeamBuff GetTouristUid failed=%v", err) | |
| 848 | + resp.Result.Code = ERROR_GETUSERIDFAILED | |
| 849 | + break | |
| 850 | + } | |
| 851 | + | |
| 852 | + teamid,err := GetTeamByUuid(uuid) | |
| 853 | + if err != nil { | |
| 854 | + logger.Error("HandleAddTeamBuff GetTeamInfoFailed failed=%v", err) | |
| 855 | + resp.Result.Code = ERROR_GETTEAMINFO_FAILED | |
| 856 | + break | |
| 857 | + } | |
| 858 | + tinfo ,err := GetTeamInfo(teamid) | |
| 859 | + if err != nil { | |
| 860 | + logger.Error("HandleAddTeamBuff GetTeamInfoFailed failed=%v", err) | |
| 861 | + resp.Result.Code = ERROR_GETTEAMINFO_FAILED | |
| 862 | + break | |
| 863 | + } | |
| 864 | + //判断一下是否已经在队伍中 | |
| 865 | + inteam := tinfo.IsInTeam(uuid) | |
| 866 | + | |
| 867 | + if !inteam { | |
| 868 | + logger.Error("HandleAddTeamBuff not inteam failed=%v", err) | |
| 869 | + resp.Result.Code = ERROR_TEAMNOTINTEAM | |
| 870 | + break | |
| 871 | + } | |
| 872 | + | |
| 873 | + //处理buff | |
| 874 | + tinfo.DoAddBuffTimee(rdata.Build_type,rdata.Muti,&resp) | |
| 875 | + | |
| 876 | + | |
| 877 | + //保存队伍数据 | |
| 878 | + SaveTeamInfo(tinfo.BaseInfo.Id,tinfo) | |
| 879 | + | |
| 880 | + | |
| 881 | + resp.Result.Code = ERROR_OK | |
| 882 | + break | |
| 883 | + } | |
| 884 | + | |
| 885 | + //回包 | |
| 886 | + respstr, _ := json.Marshal(&resp) | |
| 887 | + fmt.Fprint(w, string(respstr)) | |
| 766 | 888 | } |
| 767 | 889 | \ No newline at end of file | ... | ... |