Files
game1/assets/_script/oppoUtil.js
T
tothvillar e896e2ead4 init
2026-07-09 15:04:14 +08:00

444 lines
14 KiB
JavaScript

window.ysOppo = {
createChapingOPPO: function (e, o, t) {
console.log("createchaping ");
var i = cc.view.getVisibleSize();
cc.v2(i.width / 2, i.height / 2);
var n = new cc.Node();
n.parent = cc.director.getScene();
n.zIndex = cc.macro.MAX_ZINDEX;
n.setContentSize(cc.winSize);
var a = new cc.Texture2D();
var c = new cc.SpriteFrame();
a.initWithData(new Uint8Array([0, 0, 0]), cc.Texture2D.PixelFormat.RGB888, 1, 1, cc.winSize);
c.setTexture(a);
c.setRect(cc.rect(0, 0, 20 * cc.winSize.width, 20 * cc.winSize.width));
var s = new cc.Node();
s.parent = n;
s.opacity = 1;
s.addComponent(cc.Sprite).spriteFrame = c;
s.on("touchend", function (e) {});
var l = new cc.Node();
l.parent = n;
l.x = .5 * i.width;
l.y = .5 * i.height;
var r = l.addComponent(cc.Sprite);
a = new cc.Texture2D();
c = new cc.SpriteFrame();
a.initWithData(new Uint8Array([0, 0, 0]), cc.Texture2D.PixelFormat.RGB888, 1, 1, cc.winSize);
c.setTexture(a);
c.setRect(cc.rect(0, 0, 500, 400));
r.spriteFrame = c;
r.sizeMode = cc.Sprite.SizeMode.Custom;
cc.loader.load(e, function (e, o) {
r.spriteFrame = new cc.SpriteFrame(o);
});
var d = new cc.Node();
d.parent = n;
d.x = .5 * i.width;
d.y = .5 * i.height;
var u = d.addComponent(cc.Sprite);
cc.loader.loadRes("textures/ysguanggao/bj", function (e, o) {
u.spriteFrame = new cc.SpriteFrame(o);
});
d.on(cc.Node.EventType.TOUCH_END, function (e) {
console.log("ad click");
t && t();
n.removeFromParent();
});
l.on(cc.Node.EventType.TOUCH_END, function (e) {
console.log("ad click");
t && t();
n.removeFromParent();
});
var h = new cc.Node();
h.parent = n;
h.x = i.width / 2 + 230;
h.y = i.height / 2 + 160;
h.sizeMode = cc.Sprite.SizeMode.Custom;
cc.loader.loadRes("textures/ysguanggao/native_3", function (e, o) {
h.addComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(o);
});
var f = new cc.Node();
f.parent = n;
f.x = i.width / 2 + 210;
f.y = i.height / 2 - 90;
cc.loader.loadRes("textures/ysguanggao/native_1", function (e, o) {
f.addComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(o);
});
var g = new cc.Node();
g.parent = n;
g.x = i.width / 2;
g.y = i.height / 2 - 150;
g.scale = 1.2;
cc.loader.loadRes("textures/ysguanggao/native_5", function (e, o) {
g.addComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(o);
});
g.on(cc.Node.EventType.TOUCH_END, function (e) {
console.log("ad click");
t && t();
n.removeFromParent();
});
var p = new cc.Node();
p.parent = n;
p.opacity = 1;
p.x = i.width / 2 + 230;
p.y = i.height / 2 + 160;
p.scale = window.ServerConfigBd.closeBtnScale;
cc.loader.loadRes("textures/ysguanggao/native_3", function (e, o) {
p.addComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(o);
});
p.on(cc.Node.EventType.TOUCH_END, function (e) {
console.log("closeBtn click");
o && o();
n.removeFromParent();
});
return n;
},
createBannerOppo: function (e, o, t) {
var i = cc.view.getVisibleSize();
cc.v2(i.width / 2, i.height / 2);
var n = new cc.Node();
n.parent = cc.director.getScene();
n.zIndex = cc.macro.MAX_ZINDEX;
n.setContentSize(cc.winSize);
var a = new cc.Node();
a.parent = n;
a.x = .5 * i.width;
a.y = .05 * i.height;
var c = a.addComponent(cc.Sprite);
var s = new cc.Texture2D();
var l = new cc.SpriteFrame();
s.initWithData(new Uint8Array([0, 0, 0]), cc.Texture2D.PixelFormat.RGB888, 1, 1, cc.winSize);
l.setTexture(s);
l.setRect(cc.rect(0, 0, cc.winSize.width, .1 * cc.winSize.height));
c.spriteFrame = l;
c.sizeMode = cc.Sprite.SizeMode.CUSTOM;
cc.loader.load(e, function (e, o) {
c.spriteFrame = new cc.SpriteFrame(o);
});
a.on(cc.Node.EventType.TOUCH_END, function (e) {
console.log("ad click");
t && t();
n.removeFromParent();
});
var r = new cc.Node();
r.parent = n;
r.x = i.width / 2 + 250;
r.y = .09 * i.height;
cc.loader.loadRes("textures/ysguanggao/native_3", function (e, o) {
r.addComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(o);
});
var d = new cc.Node();
d.parent = n;
d.x = i.width / 2 + 250;
d.y = .02 * i.height;
cc.loader.loadRes("textures/ysguanggao/native_1", function (e, o) {
d.addComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(o);
});
r.on(cc.Node.EventType.TOUCH_END, function (e) {
console.log("closeBtn click");
o && o();
n.removeFromParent();
});
return n;
}
};
window.oppoUtil = {
shipinID: "481512",
chapingID: "",
bannerID: "481506",
yuanshengID1: "481511",
yuanshengID2: "481510",
yuanshengID3: "481509",
MoreID: "481549",
mobanID1: "",
mobanID2: "",
mobanID3: "",
rewardedVideoAd: null,
AdSuccess: function () {
if (null != oppoUtil.videoCallback) {
oppoUtil.videoCallback();
oppoUtil.videoCallback = null;
}
},
Adfail: function () {
if (null != oppoUtil.videoCallbackfail) {
oppoUtil.videoCallbackfail();
oppoUtil.videoCallbackfail = null;
}
},
yuanshengIndex: 0,
ysOppoADK: null,
isVideo: false,
isFrist: true,
isShowChaping: 0,
portalInstance: null,
bannerNative: null,
chapingnativeAd: null,
lfenzhong: false,
SHOWIndex: 0,
initQQShow: function () {
window.ServerConfigBd = window.GameConfig;
setTimeout(function () {
oppoUtil.lfenzhong = true;
}, window.GameConfig.NativeTime);
1 == window.ServerConfigBd.updateAd && setInterval(function () {
oppoUtil.createNativead();
}, window.ServerConfigBd.updateTime);
},
getVideoAd: function (e, o) {
this.videoCallback = e;
this.videoCallbackfail = o;
if (null == oppoUtil.rewardedVideoAd) {
oppoUtil.rewardedVideoAd = qg.createRewardedVideoAd({
adUnitId: oppoUtil.shipinID
});
} else {
oppoUtil.rewardedVideoAd.offLoad();
oppoUtil.rewardedVideoAd.offError();
oppoUtil.rewardedVideoAd.offClose();
}
oppoUtil.rewardedVideoAd.load().then(function () {
console.log("激励视频广告load成功");
oppoUtil.rewardedVideoAd.show().then(function () {
console.log("激励视频广告显示成功");
oppoUtil.isVideo = true;
}).catch(function (e) {
console.log("激励视频广告显示失败", e);
oppoUtil.Adfail();
qg.showToast({
message: "稍后再试。。"
});
});
}).catch(function (e) {
console.log("激励视频广告load失败" + JSON.stringify(e));
oppoUtil.Adfail();
qg.showToast({
title: "稍后再试。。",
icon: "none",
duration: 2e3
});
});
oppoUtil.rewardedVideoAd.onError(function (e) {
console.log(e);
oppoUtil.Adfail();
});
oppoUtil.rewardedVideoAd.onClose(function (e) {
if (e && e.isEnded) {
oppoUtil.isVideo = false;
oppoUtil.AdSuccess();
console.log("vivo videoad play success22222222222222");
} else {
if (window.ServerConfigBd.showModal) {
window.qg.showModal({
title: "未观看完视频",
content: "观看完视频才能获得奖励哦",
success: function (e) {
if (e.confirm) {
oppoUtil.rewardedVideoAd.show().then(function () {
console.log("激励视频 广告显示");
}).catch(function () {
oppoUtil.rewardedVideoAd.load().then(function () {
oppoUtil.rewardedVideoAd.show();
}).catch(function (e) {
oppoUtil.Adfail();
console.log("激励视频 广告显示失败");
});
});
} else {
e.cancel && oppoUtil.Adfail();
}
},
fail: function (e) {
oppoUtil.Adfail();
}
}), console.log("激励视频广告取消关闭,不发放奖励");
} else {
oppoUtil.Adfail();
}
oppoUtil.isVideo = false;
console.log("vivo videoad play cancel");
}
});
},
GaiLv: function (e) {
return 1 + Math.floor(100 * Math.random()) <= e;
},
showAd_Banner: function () {
if (oppoUtil.lfenzhong) {
oppoUtil.clearAD();
oppoUtil.isShowChaping++;
if (oppoUtil.GaiLv(window.ServerConfigBd.ShowPopCp)) {
oppoUtil.createNativeadChaping();
} else {
oppoUtil.createNativeadBanner();
}
} else {
console.log("1分钟限制中-------");
}
},
showMoreGame: function () {
oppoUtil.clearAD();
if (oppoUtil.portalInstance) {
oppoUtil.portalInstance.show();
} else {
oppoUtil.yujiazai();
qg.showToast({
title: "暂时没有更多游戏",
icon: "none",
duration: 2e3
});
}
},
yujiazai: function () {
var e = window.qg.createGamePortalAd({
adUnitId: oppoUtil.MoreID
});
e.onLoad(function () {
oppoUtil.portalInstance = e;
});
e.onClose(function () {
console.log("关闭更多游戏");
if (oppoUtil.portalInstance) {
oppoUtil.portalInstance.destroy();
oppoUtil.portalInstance = null;
}
oppoUtil.yujiazai();
});
e.load();
},
showAdInGame: function () {
if (oppoUtil.lfenzhong) {
oppoUtil.GaiLv(window.ServerConfigBd.ShowInGameCp) && oppoUtil.createNativeadChaping(false);
} else {
console.log("1分钟限制中-------");
}
},
showAd_ChaPing: function () {
if (oppoUtil.lfenzhong) {
if (oppoUtil.GaiLv(window.ServerConfigBd.ShowJieSuanCp)) {
oppoUtil.createNativeadChaping();
} else {
oppoUtil.createNativeadBanner();
}
} else {
console.log("1分钟限制中-------");
}
},
showBanner: function () {
oppoUtil.clearAD();
oppoUtil.bannerAd = qg.createBannerAd({
adUnitId: oppoUtil.bannerID
});
oppoUtil.bannerAd.onError(function (e) {
console.log(e);
oppoUtil.GaiLv(window.ServerConfigBd.quitShow) && oppoUtil.createNativeadBanner();
});
oppoUtil.bannerAd.show();
},
closeBanner: function () {
oppoUtil.clearAD();
},
clearAD: function () {
oppoUtil.bannerAd && oppoUtil.bannerAd.hide();
oppoUtil.ysOppoADK && oppoUtil.ysOppoADK.destroy();
},
createNativeadChaping: function () {
var e = arguments.length > 0 && undefined !== arguments[0] && arguments[0];
if (oppoUtil.chapingnativeAd) {
oppoUtil.chapingnativeAd.offLoad();
oppoUtil.chapingnativeAd.offError();
oppoUtil.chapingnativeAd = null;
}
var o = [oppoUtil.yuanshengID1, oppoUtil.yuanshengID2, oppoUtil.yuanshengID3];
oppoUtil.yuanshengIndex += 1;
oppoUtil.yuanshengIndex >= o.length && (oppoUtil.yuanshengIndex = 0);
oppoUtil.chapingnativeAd = qg.createNativeAd({
adUnitId: o[oppoUtil.yuanshengIndex]
});
oppoUtil.chapingnativeAd.onLoad(function (o) {
oppoUtil.chapingnativeAd.offLoad();
oppoUtil.chapingnativeAd.reportAdShow({
adId: o.adList[0].adId
});
oppoUtil.clearAD();
oppoUtil.ysOppoADK = ysOppo.createChapingOPPO(o.adList[0].imgUrlList[0], function () {
oppoUtil.chapingnativeAd.offLoad();
oppoUtil.chapingnativeAd.offError();
oppoUtil.ysOppoADK = null;
oppoUtil.GaiLv(window.ServerConfigBd.quitShow) && !e && oppoUtil.createNativeadBanner();
}, function () {
oppoUtil.chapingnativeAd.reportAdClick({
adId: o.adList[0].adId
});
oppoUtil.chapingnativeAd.offLoad();
oppoUtil.chapingnativeAd.offError();
oppoUtil.ysOppoADK = null;
oppoUtil.GaiLv(window.ServerConfigBd.quitShow) && !e && oppoUtil.createNativeadBanner();
});
});
oppoUtil.chapingnativeAd.onError(function (o) {
oppoUtil.chapingnativeAd.offLoad();
oppoUtil.chapingnativeAd.offError();
oppoUtil.chapingnativeAd = null;
console.log("插屏显示错误了----" + JSON.stringify(o));
oppoUtil.GaiLv(window.ServerConfigBd.quitShow) && !e && oppoUtil.showBanner();
});
oppoUtil.chapingnativeAd.load();
},
createNativeadBanner: function () {
if (oppoUtil.bannerNative) {
oppoUtil.bannerNative.offLoad();
oppoUtil.bannerNative.offError();
oppoUtil.bannerNative = null;
}
oppoUtil.clearAD();
var e = [oppoUtil.yuanshengID1, oppoUtil.yuanshengID2, oppoUtil.yuanshengID3];
oppoUtil.yuanshengIndex += 1;
oppoUtil.yuanshengIndex >= e.length && (oppoUtil.yuanshengIndex = 0);
oppoUtil.bannerNative = qg.createNativeAd({
adUnitId: e[oppoUtil.yuanshengIndex]
});
oppoUtil.bannerNative.onLoad(function (e) {
oppoUtil.bannerNative.reportAdShow({
adId: e.adList[0].adId
});
oppoUtil.clearAD();
oppoUtil.ysOppoADK = ysOppo.createBannerOppo(e.adList[0].imgUrlList[0], function () {
oppoUtil.bannerNative.offLoad();
oppoUtil.bannerNative.offError();
oppoUtil.ysOppoADK = null;
}, function () {
oppoUtil.bannerNative.reportAdClick({
adId: e.adList[0].adId
});
oppoUtil.bannerNative.offLoad();
oppoUtil.bannerNative.offError();
oppoUtil.ysOppoADK = null;
});
});
oppoUtil.bannerNative.onError(function (e) {
oppoUtil.bannerNative.offLoad();
oppoUtil.bannerNative.offError();
console.log("调用banner错误了===" + JSON.stringify(e));
oppoUtil.GaiLv(window.ServerConfigBd.quitShow) && oppoUtil.showBanner();
});
oppoUtil.bannerNative.load();
},
createNativead: function () {
var e = [oppoUtil.yuanshengID1, oppoUtil.yuanshengID2, oppoUtil.yuanshengID3];
oppoUtil.yuanshengIndex += 1;
oppoUtil.yuanshengIndex >= e.length && (oppoUtil.yuanshengIndex = 0);
var o = qg.createNativeAd({
adUnitId: e[oppoUtil.yuanshengIndex]
});
o.onLoad(function (e) {
o.offLoad();
o.reportAdShow({
adId: e.adList[0].adId
});
});
o.onError(function (e) {});
o.load();
}
};